// JavaScript Document
if(window.location.host=='localhost')
{
	var root_url='http://'+window.location.host+'/us/';
}
else
{
	var root_url='http://'+window.location.host+'/us/';
}

var glb_extension=new Array('zip','doc','docx','xls','xlsx','ppt','pptx','rtf','txt','jpg','jpeg','gif','png');
var assign_val='';

var globalDivId='';
function show_div(divid)
{
	$("#"+divid+":hidden:first").fadeIn("fast");
}
function hide_div(divid)
{
	$("#"+divid).fadeOut("fast");
}

function set_div_height(divid)
{
	var ht=document.body.scrollHeight;
	document.getElementById(divid).style.height=ht+"px";
	alert(ht);
}
function set_div_position(divid,w,h)
{
	var scr_ht=screen.height;
	var scr_wd=screen.width;
	var ht=parseInt(scr_ht)/2;
	var wd=parseInt(scr_wd)/2;
	
	
	w=parseInt(w)/2;
	h=parseInt(h)/2;
	
	var tp=parseInt(ht)-parseInt(h)-100;
	var lt=parseInt(wd)-parseInt(w);
	
	document.getElementById(divid).style.left=lt+"px";
	document.getElementById(divid).style.top=tp+"px";
	document.getElementById(divid).style.position='fixed';
}


function show_popup_div(divid,w,h)
{
	globalDivId=divid;
	set_div_position(divid,w,h);
	show_div(divid);
}

function hide_div_from_onclick(divid)
{
	hide_div(globalDivId);
	hide_div(divid);
}


function char_count(t,id,maxchar)
{
	var len=t.value.length;
	var charleft=parseInt(maxchar)-parseInt(len);
	if(parseInt(len)>parseInt(maxchar))
	{
		var val = t.value.substring(0,maxchar);
		 t.value =val;
		return false;
	}
	document.getElementById(id).innerHTML=charleft+" Characters left";
	
}

function get_file_extension(val)
{
	var ext='';
	if(val!='')
	{
		var arr=val.split('.');
		ext=arr[parseInt(arr.length)-1];
	}
	return ext;

}
function in_array(arr,val)
{
	var len=arr.length;
	var flag=1;
	for(var i=0;i<len;i++)
	{
		if(arr[i]==val)
		{
			flag=0;
		}
	}
	return flag;
}


function numbersonly(myfield, e, dec)
{
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);

// control keys
if ((key==null) || (key==0) || (key==8) || 
    (key==9) || (key==13) || (key==27) )
   return true;

// numbers
else if ((("0123456789").indexOf(keychar) > -1))
   return true;

// decimal point jump
else if (dec && (keychar == "."))
   {
   myfield.form.elements[dec].focus();
   return false;
   }
else
   return false;
}

function validateEmailv2(email)
{
// a very simple email validation checking. 
// you can add more complex email checking if it helps 
    if(email.length <= 0)
	{
	  return true;
	}
    var splitted = email.match("^(.+)@(.+)$");
    if(splitted == null) return false;
    if(splitted[1] != null )
    {
      var regexp_user=/^\"?[\w-_\.]*\"?$/;
      if(splitted[1].match(regexp_user) == null) return false;
    }
    if(splitted[2] != null)
    {
      var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
      if(splitted[2].match(regexp_domain) == null) 
      {
	    var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
	    if(splitted[2].match(regexp_ip) == null) return false;
      }// if
      return true;
    }
return false;
}

function valid_order_from()
{
	if(document.getElementById('is_ship').checked==true && document.getElementById('is_ship').value=='Y' && document.getElementById('shipping_code').value=='')
	{
		alert("Please enter your shipping code");
		return false;
	}
	else if(document.getElementById('is_ship2').checked==true && document.getElementById('is_ship2').value=='N' && document.getElementById('ups').value=='')
	{
		alert("Please select your shipping method");
		return false;
	}
	else
	{
		return true;
	}
}

