/*
Version 2.0
*/

var to_swap = 0;
var isIndex = false;
// ==============================================================================================
function i_swap(iname){
	// only run on index page
	clearTimeout(to_swap);
	if(isIndex){
		if (iname == "") {
			to_swap=setTimeout("MM_swapImage('index_img','','" + defaultImg + "')",2500);
		}else{
			iname= 'images/i_'+iname+'.jpg';
			MM_swapImage('index_img','',iname);
		}
	}
}
// -------------------------------------------------------------
function costsWin(){
	mywindow = window.open ("setup.php","costs","location=0,status=0,scrollbars=0,width=570,height=358");
	
}
// -------------------------------------------------------------

function noEnterKey() {
	//alert(window.event.keyCode)
	if (window.event.keyCode == 13){
		alert("Enter key has been disabled.")
		window.event.keyCode =0;
	}
} 

// -------------------------------------------------------------
function requestQuote(mode) {
	//showHideDiv("prod_request");
	if(mode == "hide"){
		showHide("product_request","none");
		showHide("product_specs","block");
	}else{
		showHide("product_specs","none");
		showHide("product_request","block");
	}
}
// -------------------------------------------------------------

function showHide(divID, mode) {
	document.getElementById(divID).style.display = mode;
}
// -------------------------------------------------------------
function moveToTop(){
	document.getElementById("container").scrollTop = 0; //It scrolls to top;
}
// -------------------------------------------------------------
function writeEmail(emName,emHost,emSubject, emClass, emText){
	/*  outputs email link : emClass and emText are optional
		emClass is the name of the class for the <a> tag
		emText is the text shown - defaults to email address
	*/
	var emClass = (emClass == null) ? "" : 'class="'+ emClass +'"';
	var emText = (emText == null) ? emName + "@" +emHost : emText;
	document.write ('<a href="mailto:' + emName + '@' + emHost + emSubject +'"' + emClass + ' onClick="doTracking()">');
	document.write (emText + '</a>');
}
// -------------------------------------------------------------

function findPos(obj) {
	this.X = obj.offsetLeft;
	this.Y = obj.offsetTop;
	while(obj.offsetParent){
		this.X=this.X+obj.offsetParent.offsetLeft;
		this.Y=this.Y+obj.offsetParent.offsetTop;
		if(obj==document.getElementsByTagName('body')[0]){break}
		else{obj=obj.offsetParent;}
	}
	return this
}
// -------------------------------------------------------------

function browserType() {
    t = "Other";
    if ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 4)) 
		t = "NS";
    if ((navigator.appName == "Microsoft Internet Explorer") &&	(parseInt(navigator.appVersion) >= 4)) 
		t = "IE";
    return t;
}
var thisBrowser = browserType();
// -------------------------------------------------------------
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
// -------------------------------------------------------------

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
// number formatting function
// copyright Stephen Chapman 24th March 2006, 10th February 2007
// permission to use this function is granted provided
// that this copyright notice is retained intact
// -------------------------------------------------------------

function formatNumber(num,dec,thou,pnt,curr1,curr2,n1,n2) {var x = Math.round(num * Math.pow(10,dec));if (x >= 0) n1=n2='';var y = (''+Math.abs(x)).split('');var z = y.length - dec; if (z<0) z--; for(var i = z; i < 0; i++) y.unshift('0');y.splice(z, 0, pnt); if(y[0] == pnt) y.unshift('0'); while (z > 3) {z-=3; y.splice(z,0,thou);}var r = curr1+n1+y.join('')+n2+curr2;return r;}
// -------------------------------------------------------------
function doSearchForm(){
	var frm  =document.frm_search;
	var t_or_f = true;
	if(frm.search_phrase.value == ""){
		t_or_f = false;
		alert("Please enter a word or phrase to search for.");
	}
	if(t_or_f){
		showHide("div_search_fields","none");
		showHide("div_searching","block");
		frm.submit();	
	}
}

// -------------------------------------------------------------

function info_price(){
	winRef = window.open('/price-guarantee.php','mywindow','width=400,height=260,left=50,top=50,screenX=50,screenY=50')
	
}

//----------------------------------------------------------------
function doTracking(){
	info_popup('mailer.php', 1);
}
function info_popup(page, height){
	winRef = window.open(pth +page,'infowindow','width=450,height='+height+',left=50,top=50,screenX=50,screenY=50')
}

//----------------------------------------------------------------

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
//----------------------------------------------------------------
function checkFormQuickQuote(){
	var err = "We're sorry but you need to tell us...\n\n" ;
	var frm = document.form_quick_quote;
  	var myTelNo = frm.phone.value;
	var t_or_f = true;
	
	var v = frm.quantity.value
	if (v == "" || isNaN(v)){
		t_or_f = false;
		err = err + "- How many you need\n"
	}else{
		if(v < breakQuantity[1]){
			t_or_f = false;
			err = err + "- Quantity : Sorry but the quantity you require is below our minimum order levels for this product.\nMinimum order quantity is " + breakQuantity[1] + " units.\n\n"
		}
	}
	
	if(frm.name.value == ""){
		t_or_f = false;
		err = err + "- Your name\n"
	}
  	if (!checkUKTelephone (myTelNo))  err = err + " - Telephone number (" + telNumberErrors[telNumberErrorNo] + ")\n";

	if(frm.email.value == ""){
		t_or_f = false;
		err = err + "- Your email address\n"
	}


	if(frm._security_code.value == ""){
		t_or_f = false;
		err = err + "- Security code : Please enter the code as shown\n"
	}

	if(t_or_f){
/*
		if(confirm("Are you an existing Promo-USB / Buyking customer?")){
			frm.existing_customer.value = "Yes"	
		}
*/
		frm.btn_submit.value = "Submitting";
		frm.btn_submit.disabled = true;

		frm.submit();	
	}else{
		alert(err)
	}

}
// -------------------------------------------------------------
function checkFormQuickContact(){
	var t_or_f = true;
	var err = "";
	var frm = document.form_quick_quote;
	var v = frm.quantity.value;
	if (v == "" || isNaN(v)){
		t_or_f = false;
		err = err + "- how many you need\n"
	}
	

	if(frm.name.value == ""){
		t_or_f = false;
		err = err + "- Your name\n"
	}

	if(frm.email.value == "" && frm.phone.value == ""){
		t_or_f = false;
		err = err + "- Your email address or telephone number\n"
	}

	if(frm._security_code.value == ""){
		t_or_f = false;
		err = err + "- Security code - Please enter the code as shown\n"
	}


	if(t_or_f){
		frm.btn_submit.value = "Submitting";
		frm.btn_submit.disabled = true;
		frm.submit();	
	}else{
		err = "We're sorry but you need to tell us...\n\n" + err
		alert(err)
	}

}

//--------------------------------------------------------------------------
function checkFormAdvQuote(){
	var t_or_f = true;
	var frm = document.form_quote_adv;
	var err = "We're sorry but you need to tell us...\n\n";
	
	var v = parseInt(frm.quantity.value)
	if (v == "" || isNaN(v)){
		t_or_f = false;
		err = err + "- How many you need\n"
	}
	
	if(frm.name.value == ""){
		t_or_f = false;
		err = err + "- Your name\n"
	}

	if(frm.email.value == "" && frm.phone.value == ""){
		t_or_f = false;
		err = err + "- Your email address or telephone number\n"
	}
	if(v < parseInt(frm._minQuantity.value)){
		t_or_f = false;
		err = "Sorry but the quantity you require is below our minimum order levels for this product.\nMinimum order quantity is " + frm._minQuantity.value + " units."
	}

	if(frm._security_code.value == ""){
		t_or_f = false;
		err = err + "- Security code - Please enter the code as shown\n"
	}

	if(t_or_f){
		frm.btn_submit.value = "Submitting";
		frm.btn_submit.disabled = true;
		frm.submit();	
	}else{
		alert(err)
	}

}
// ----------------------------------------------------------------
function checkFormContact(){
	var frm = document.frmcontact;
	var errmsg = "";
	if(frm.name.value == "") errmsg = errmsg + " - Your name\n";
	if(frm.phone.value == "" && frm.email.value == "") errmsg = errmsg + " - Telephone number or Email address\n";
	if(frm.message.value == "") errmsg = errmsg + " - your message / request\n";
	if(frm._security_code.value == ""){
		errmsg = errmsg + " - Security code : Please enter the code as shown\n"
	}

	if(errmsg == "") {
		frm.submit();
	}else{
		errmsg = "Sorry but the form is incomplete. \n\nPlease check the following fields...\n" + errmsg;
		alert(errmsg);
	}
}
//-----------------------------------------------------------------
function checkQty(){
	var frm = document.form_quick_quote;
	var t_or_f = true;
	if(parseInt(frm.quantity.value)<breakQuantity[1]) {
		alert("Quantity too low!\n\nSorry but the minimum quantity for this product is " + breakQuantity[1]);
		t_or_f = false
	}
	return t_or_f;
}
// -------------------------------------------------------------

function securityinfo(){
	alert("What's this?\n\nThis is a 5-digit security code that helps us to ensure we get real enquiries from real people.\n\nIf you cannot read the code easily, use the speaker icon to download an audio file that will read the code to you.\nAlternatively, you can click the 'Refresh Image' icon which will load a new code for you. This can be done as many times as you wish.\n\nWe apologise for any inconvenience this may cause but due to other, inconsiderate marketers, we have to protect ourselves again spam and other malicious emails.\n\n")
}
// -------------------------------------------------------------
