var oWindowsT = new Object();

function popup(url, windowname, w, h)
{
if (!w) w = 500;
if (!h) h = 700;
if (! window.focus)
	return true;
window.open(url, windowname, 'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width='+w+',height='+h);
}

function openWindowCheck(url, windowname, w, h) {
	//open window
	if (!w) w = 500;
	if (!h) h = 700;
	if (! window.focus)
		return true;
	handle = window.open(url, windowname, 'resizable=yes,scrollbars=yes,width='+w+',height='+h);
	
	//add  handle to window object holder
	oWindowsT[windowname] = handle;
	
	//check if the window opened
	setTimeout("checkOpen(\"" + windowname + "\")",1000);
}

function checkOpen(pageId) {
 try {
        if ( (!oWindowsT[pageId]) || (oWindowsT[pageId].closed) ) {
		//handle code how ever you want
		var elem = document.getElementById("popupmsg");
		elem.style.display = "block";
	} else {
		var elem = document.getElementById("popupmsg");
		elem.style.display = "none";
	}
     }catch(e){
		//if unable to read var show message
     }
}

function closeIt() {
   document.getElementById("popupmsg").style.display = "none";
}
//open a window
function openWin(pageId) { 
	switch (pageId) {
		case "page1":
			//set window properties
			var sPar = "width=500,height=500";
			handle = window.open("http://cnn.com",pageId,sPar);
			break;
		case "page2":
			//add code for another id
			//handle = window.open(sURL,page,sPar);
			break;
		default:
	}
	//add  handle to window object holder
	oWindowsT[pageId] = handle;
}

function showHide(id,action)
{
	obj = document.getElementById(id);
	if (!action) action = "show";
	if (action=="show") obj.style.display="block";
	else if (action=="hide") obj.style.display="none";
}

function searchboxClick(){
 document.getElementById('search-box').value="";
 document.getElementById('search-box').style.color="#252525";
}

function searchboxClickout() {
 document.getElementById('search-box').style.color="#A0A0A0";
}

function setDeviceOptions(formName,selectName)
{
	selForm = document.getElementById(formName);
	options = eval("document." + formName + "." + selectName + ".options");
	//alert("Options: " + options);
	manf = options[eval("document." + formName + "." + selectName + ".selectedIndex")].value;
	//alert("Manf: " + manf);
	// reset device option list
	//alert("Resetting options...");
	selForm.device_uid.options.length = 0;
	//alert("Determining devices...");
	if (manf != "Pick_One...") {
		// get devices
		devices = eval("document." + formName + "." + manf + ".value");
		//alert("Devices: " + devices);
		// get device uids and names
		dev_array=devices.split(",");
		for (i=0; i < dev_array.length - 1; i++) {
			sec_ar = dev_array[i].split("=>");
			//alert(sec_ar[1] + "*" + sec_ar[0]);
			selForm.device_uid.options[i] = new Option(sec_ar[1],sec_ar[0]);
		}
	}
	else {
		selForm.device_uid.options[0] = new Option("Pick One...","Pick_One...");
	}
}

function buyNow(device_uid, product)
{
	window.location.href = "buynow.php?device_uid="+device_uid+"&product="+product;
}

function parentWin(url)
{
	window.opener.location.href = url;
	window.close();
}
function getKeyCode(e) 
{
	var key = (window.event) ? event.keyCode : e.which;   
	if (window.event) key = event.keyCode   
	else key = e.which   // Was key that was pressed a numeric character (0-9) , backspace (8), or tab (9)?  
	return key;
}
function CheckNumeric(e) 
{   
	var key = getKeyCode(e);
	if ( key > 32 && key < 58 || key > 90 && key < 106 || key == 8 || key == 9 || key == 17 || key == 18 ) return; // if so, do nothing   
	else {
		if (window.event) //IE       
			window.event.returnValue = null;     
	else //Firefox       
		e.preventDefault(); 
	}
}

function nextField(e,id,nextId,numChars)
{
	var key = getKeyCode(e);
	if ( key > 32 && key < 48 || key == 8 || key == 9 || key == 16 ) return; // if key = backspace or tab, don't set new focus
	else if (document.getElementById(id).value.length==numChars) document.getElementById(nextId).focus(); //document.sms_form.eval(nextId).focus;
}
function isValidEmail(string) {
  if (string.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) != -1)
	return true;
  else
	return false;
}