/*--------------------------------------------
//
// scripts.js ver. 1.1 ES3 TM
// Summary: General Scripts
//
//------------------------------------------*/

// Global Variables

var ie = (document.all)?true:false;									// IE 4+
var ns = (document.layers)?true:false;	
var moz = (document.getElementById && !document.all)?true:false;	// Mozilla 5.x / NS 6


function sendSearch(){
	var url = document.getElementById("brandurl").value;
	if (document.getElementById("navSearchInput").value != ""){
		document.location.href = "http://" + url + "/results.aspx?searchFor=" + document.getElementById("navSearchInput").value;
	}
}

function handleEnter() {
 var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
 if (keyCode == 13) {
   sendSearch();
 }
}


var myWindow;
function openWin(url,w,h) {
	var	ranNum=parseInt(Math.random()*255);
	/*
	w = 650;
	h = 600;
	*/
	l=screen.width/2-w/2;
	t=screen.height/2-h/2;
	
	if (typeof myWindow == "object") {
		myWindow.close();	
	}
	myWindow = window.open(url,'admintronwin'+ranNum,'top='+t+',left='+l+',height='+h+',width='+w+',noresize,scrollbars=yes,status=yes');
}

 function submitType(type){
	if (type == '3'){
		//openWin('/caltotal.aspx?txtPromoCode='+document.forms.catinfo.txtPin1.value+document.forms.catinfo.txtPin2.value+document.forms.catinfo.txtPin3.value+'','430','280')
		openWin('/caltotal.aspx','430','280')
		document.forms.catinfo.submitType.value = '1';
		document.forms.catinfo.submit();
	}
	else{
		document.forms.catinfo.submitType.value = type;
		document.forms.catinfo.submit();
	}
 }
 
 //AutoTab the field to the next one
var code_field_length=0;
function TabNext(obj,event,len,next_field) {
	if (event == "down") {
		//obj.value=obj.value.toUpperCase();
		code_field_length=obj.value.length;
		}
	else if (event == "up") {
		if (obj.value.length != code_field_length) {
			code_field_length=obj.value.length;
			if (code_field_length == len) {
				obj.value=obj.value.toUpperCase();
				next_field.focus();
				}
			}
		}
	}


function Trim(s) 
{
  // Remove leading spaces and carriage returns
  while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
  {
    s = s.substring(1,s.length);
  }
  // Remove trailing spaces and carriage returns
  while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
  {
    s = s.substring(0,s.length-1);
  }
  return s;
}

// Wait Function for pasting into multiple fields
function pasteCode() {
	setTimeout("pasteCodeAfter()",10);
}

//Paste Into mulitple fields (PIN)
function pasteCodeAfter() {
	var code = Trim(window.clipboardData.getData("Text"));
	var codeSplit;
	if (code.length == 20) {
		codeSplit = code.split("-");
		document.forms[0].txtPin1.value=codeSplit[0];
		document.forms[0].txtPin2.value=codeSplit[1];
		document.forms[0].txtPin3.value=codeSplit[2];
		document.forms[0].txtPin3.focus();
	}	
}