
var showResponseId = '';
var frmName = '';
var xmlHttp = null;

/*function Trim(val)
{
	val = val.replace(new RegExp(/^\s+/),""); // START
	val = val.replace(new RegExp(/\s+$/),""); // END
	return val
}*/

function ajax(val,responseId,actionUrl,toAttach,resultType,formName)
{
	if(Trim(responseId) != '')
	{
		showResponseId = responseId;
	}

	if(formName != '')
	{
		frmName = formName;
	}
	
	 xmlHttp=GetXmlHttp();
	
	if(xmlHttp == null)
	{
		//alert("Your browser do not support ajax");
		return false
	}
	
	if(formName != 'header_search')
	{
		switch(responseId)
		{
			case 'zipcode':
				val += '/'+document.getElementById('state').value
			break;
			case 'zipErrorId':
			//	val += '/'+document.getElementById('country').value
				val += '/'+document.forms['spRegistration_1'].elements['country'].value;
			break;
		}
	}
	
	switch(toAttach)
	{
		case 1:
			var url = actionUrl+val
		break;
		case 2:
			var url = actionUrl
		break;
	}
	
	switch(resultType)
	{
		case 'dropdown':
			xmlHttp.onreadystatechange = dropDown
		break;
		case 'dropDownWithOptgroup':
			xmlHttp.onreadystatechange = dropDownWithOptgroup
		break;
		case 'callFuntion':
			xmlHttp.onreadystatechange = handleCustomeResponse
		break;
		default:
			xmlHttp.onreadystatechange = handleResponse
		break;
	}
	
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function GetXmlHttp()
{
  var xmlHttp=null;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  	    }
    catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
    
  return xmlHttp;
}

function dropDown()
{
	if(xmlHttp.readyState == 4)
	{
		if(xmlHttp.responseText =='DB_error')
		{
			document.getElementById(showResponseId).options.length = 0;
			document.getElementById(showResponseId).options[0] = new Option( '-- Select --'  , '0');
			return false;
		}
		
		document.getElementById(showResponseId).options.length = 0;
		var Answers = eval('('+xmlHttp.responseText+')');
		document.forms[frmName].elements[showResponseId].options[0] = new Option( '-- Select --'  , '0');		
		
		if(Answers == null )
		{
			
		}	
		else
		{
			if(Answers.length == 1 )
			{
				document.forms[frmName].elements[showResponseId].options[1] = new Option( Answers[0][0]  , Answers[0][1]);
			}	
			
			else 
			{	
				
				if(Answers[1].length > 1)
				{
					for(var i = 1 ; i <=Answers.length; i++)
					{
						//document.getElementById(showResponseId).options[i] = new Option( Answers[i][0]  , Answers[i][1]);
						document.forms[frmName].elements[showResponseId].options[i] = new Option( Answers[i-1][0]  , Answers[i-1][1]);
					}
				}
				else
				{
					for(var i = 0 ; i < Answers.length; i++)
					{
						//document.getElementById(showResponseId).options[i] = new Option( Answers[i][0]  , Answers[i][0]);
						document.forms[frmName].elements[showResponseId].options[i+1] = new Option( Answers[i][0]  , Answers[i][0]);
					}
				}

/*				for(var i = 1 ; i <=Answers.length; i++)
				{
					document.getElementById(showResponseId).options[i] = new Option( Answers[i-1][0]  , Answers[i][1]);
					//document.forms[frmName].elements[showResponseId].options[i] = new Option( Answers[i][0]  , Answers[i][1]);
				}
*/	
			}
		}	
	}
}


function dropDownWithOptgroup()
{
	if(xmlHttp.readyState == 4)
	{
		if(xmlHttp.responseText == 'DB_error')
		{
			document.forms[frmName].elements[showResponseId].options[0] = new Option( '-- Select --'  , '0');		
			return false;
		}
		else
		{	
			document.getElementById(showResponseId).options.length = 0;
			var Answers = xmlHttp.responseText.split('>');
		//	alert(Answers);
			objSelect=document.forms[frmName].elements[showResponseId];
			for(var i = 0 ; i <Answers.length; i++)
			{
				var optGroup = document.createElement('optgroup');
				var optAndOptions = Answers[i].split('|');
				optGroup.label = optAndOptions[0];
				objSelect.appendChild(optGroup);
				var innerOptions = optAndOptions[1].split(',');
				for(var k = 0 ; k <innerOptions.length; k++)
				{
					var iOptions = innerOptions[k].split('#');
					for(var l = 0 ; l <iOptions.length; l=l+2)
					{
						var objOption=document.createElement("option");
						objOption.innerHTML = iOptions[l+1];
						objOption.value = iOptions[l];
						optGroup.appendChild(objOption)
					}
				}
			}	
		}
	}
}


function handleResponse()
{
	if(xmlHttp.readyState == 4)
	{
		if(xmlHttp.responseText =='DB_error')
		{
			alert('Error in processing data');
			return false;
		}
		else
		{
			if(showResponseId != '')
			{
				document.getElementById(showResponseId).style.display = 'block';
				document.getElementById(showResponseId).innerHTML = xmlHttp.responseText;
				return true;
			}
			else
			{
				alert(xmlHttp.responseText)
			}
		}
	}
}

function handleCustomeResponse()
{
	if(xmlHttp.readyState == 4)
	{
		if(xmlHttp.responseText =='DB_error')
		{
			alert('Error in processing data');
			return false;
		}
		else
		{
			if(showResponseId != '')
			{
				setFCKEditorContent(xmlHttp.responseText);
				return true;
			}
			else
			{
				alert(xmlHttp.responseText)
			}
		}
	}
}

function resetDropdown(frmName,dropdownId)
{
	document.forms[frmName].elements[dropdownId].options.length = 0;
	document.forms[frmName].elements[dropdownId].options[0] = new Option( '-- Select --'  , '0');
	return true;
}

function resetDropdownWithOptgroup(frmName,dropdownId)
{
	var cell = document.forms[frmName].elements[dropdownId];
	if ( cell.hasChildNodes() )
	{
	    while ( cell.childNodes.length >= 1 )
	    {
	        cell.removeChild( cell.firstChild );       
	    } 
	}
	
	
	//document.forms[frmName].elements[dropdownId].options[0] = new Option( 'Select'  , '0');
	return true;
}

// open browser window
function openPopUp(url, windowName, w, h, scrollbar) {

           var winl = (screen.width - w) / 2;
           var wint = (screen.height - h) / 2;
           winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scrollbar ;
		   win = window.open(url, windowName, winprops);
           if (parseInt(navigator.appVersion) >= 4) { 
              	win.window.focus(); 
           } 
}

function showCharLen(id,showId,max,errorId)
{
	var charLen = max - document.getElementById(id).value.length
	
	if(charLen < 0)
	{
		var message ='You can enter only '+max+' max characters'
	//	alert(message);
		return false;
	}
 	if(charLen == max)
	{
		document.getElementById(showId).value = ''
	}
	else
	{
		document.getElementById(showId).value = charLen
	}
}

function checkLength(e,id,length)
{
	var charLen = length - document.getElementById(id).value.length;
	var key;
	
	
	if (window.event) 
	{
	   key = window.event.keyCode;
	}
	else if (e) 
	{
	   key = e.keyCode;
	}
	
	
	if(key == 8)
	{
		return true;
	}
	if(charLen < 0)
	{
		var str = document.getElementById(id).value.substring(0,length);
		document.getElementById(id).value = str
		return false;
	}
	if(document.getElementById(id).value.length > length)
	{
		var str = document.getElementById(id).value.substring(0,length);
		document.getElementById(id).value = str
	}
}

function setValue(id,length)
{
	var str = document.getElementById(id).value.substring(0,length);
		document.getElementById(id).value = str;
		 return true
}

function load(id)
{
	document.getElementById(id).focus();
}
//  Function Get Value of Radio Button group
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

// Checked one will checked All
function Allcheck(obj,frmname)
{
	x=obj.checked;
	var len=eval("document."+frmname+".elements.length");
	for(i=0; i<len; i++)
	{
		if(x)
		{
			eval("document."+frmname+".elements["+i+"].checked=true");
		}
		else {
			eval("document."+frmname+".elements["+i+"].checked=false");
		}
	}
}

function showThickbox(title,url)
{
	tb_show(title, url, null);
}

function stripHtml(oldString) {

   var newString = "";
   var inTag = false;
   for(var i = 0; i < oldString.length; i++) {
   
        if(oldString.charAt(i) == '<') inTag = true;
        if(oldString.charAt(i) == '>') {
              if(oldString.charAt(i+1)=="<")
              {
              		//dont do anything
	}
	else
	{
		inTag = false;
		i++;
	}
        }
   
        if(!inTag) newString += oldString.charAt(i);

   }
	newString = escape(newString);
	newString = newString.replace('nbsp',' ');
   return newString;
}
function setSorting(field)
{
	if(field == document.getElementById('field').value)
	{
		//alert(field);
		if(document.getElementById('order').value == 0)
		{
			document.getElementById('order').value = 1;
		}
		else
		{
			document.getElementById('order').value = 0;
		}
		
	}
	else
	{
		document.getElementById('field').value = field;
		document.getElementById('order').value = 0;
	}
	
	document.sortForm.submit();
}

function jsup(prVideoLink,url)
{
//	var val = document.getElementById(id).value
//	var vals = val.split('=') 
	url += '&video='+prVideoLink+'&which=this';
	
	openPopUp(url,'_blank','950','530','1')
	return true;
}

function setFocusFromTo(e,fromId,toId,fromLength)
{	var idFrom = document.getElementById(fromId);
	var idTo = document.getElementById(toId);
	var keyPressed ;
	if(window.event)
	{
		keyPressed = window.event.keyCode;
	}
    else 
    {
		keyPressed = e.which;
    }      

    keycodes = get_typo_keyboard_codes();
	
    for(key in keycodes) {
		if(keyPressed == key) {
			if(idFrom.value.length == fromLength) {
				idTo.focus();
			}
			break;
		}
	}
}


function get_typo_keyboard_codes() 
{
	var keycodes = new Array();
	keycodes['48'] =  "0";
	keycodes['49']  = "1";
	keycodes['50']  = "2";
	keycodes['51']  = "3";
	keycodes['52']  = "4";
	keycodes['53']  = "5";
	keycodes['54']  = "6";
	keycodes['55']  = "7";
	keycodes['56']  = "8";
	keycodes['57']  = "9";
	keycodes['65']  = "a";
	keycodes['66']  = "b";
	keycodes['67']  = "c";
	keycodes['68']  = "d";
	keycodes['69']  = "e";
	keycodes['70']  = "f";
	keycodes['71']  = "g";
	keycodes['72']  = "h";
	keycodes['73']  = "i";
	keycodes['74']  = "j";
	keycodes['75']  = "k";
	keycodes['76']  = "l";
	keycodes['77']  = "m";
	keycodes['78']  = "n";
	keycodes['79']  = "o";
	keycodes['80']  = "p";
	keycodes['81']  = "q";
	keycodes['82']  = "r";
	keycodes['83']  = "s";
	keycodes['84']  = "t";
	keycodes['85']  = "u";
	keycodes['86']  = "v";
	keycodes['87']  = "w";
	keycodes['88']  = "x";
	keycodes['89']  = "y";
	keycodes['90']  = "z";
	keycodes['96']  = "numpad 0";
	keycodes['97']  = "numpad 1";
	keycodes['98']  = "numpad 2";
	keycodes['99']  = "numpad 3";
	keycodes['100'] = "numpad 4";
	keycodes['101'] = "numpad 5";
	keycodes['102'] = "numpad 6";
	keycodes['103'] = "numpad 7";
	keycodes['104'] = "numpad 8";
	keycodes['105'] = "numpad 9";

	return keycodes;
}

function removeSpace(e) 
{
	var val = document.getElementById('cURL').value;
	var key;
     if(window.event)
          key = window.event.keyCode; //IE
     else
          key = e.which; //firefox     

     if(key == 32) {
     	document.getElementById('cURL').value = val
     }     
}

function get_html_translation_table(table, quote_style) {
    // http://kevin.vanzonneveld.net
    // +   original by: Philip Peterson
    // +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: noname
    // %          note: It has been decided that we're not going to add global
    // %          note: dependencies to php.js. Meaning the constants are not
    // %          note: real constants, but strings instead. integers are also supported if someone
    // %          note: chooses to create the constants themselves.
    // %          note: Table from http://www.the-art-of-web.com/html/character-codes/
    // *     example 1: get_html_translation_table('HTML_SPECIALCHARS');
    // *     returns 1: {'"': '&quot;', '&': '&amp;', '<': '&lt;', '>': '&gt;'}
    
    var entities = {}, histogram = {}, decimal = 0, symbol = '';
    var constMappingTable = {}, constMappingQuoteStyle = {};
    var useTable = {}, useQuoteStyle = {};
    
    useTable      = (table ? table.toUpperCase() : 'HTML_SPECIALCHARS');
    useQuoteStyle = (quote_style ? quote_style.toUpperCase() : 'ENT_COMPAT');
    
    // Translate arguments
    constMappingTable[0]      = 'HTML_SPECIALCHARS';
    constMappingTable[1]      = 'HTML_ENTITIES';
    constMappingQuoteStyle[0] = 'ENT_NOQUOTES';
    constMappingQuoteStyle[2] = 'ENT_COMPAT';
    constMappingQuoteStyle[3] = 'ENT_QUOTES';
    
    // Map numbers to strings for compatibilty with PHP constants
    if (!isNaN(useTable)) {
        useTable = constMappingTable[useTable];
    }
    if (!isNaN(useQuoteStyle)) {
        useQuoteStyle = constMappingQuoteStyle[useQuoteStyle];
    }
    
    if (useQuoteStyle != 'ENT_NOQUOTES') {
        entities['34'] = '&quot;';
    }
 
    if (useQuoteStyle == 'ENT_QUOTES') {
        entities['39'] = '&#039;';
    }
 
    if (useTable == 'HTML_SPECIALCHARS') {
        // ascii decimals for better compatibility
        entities['38'] = '&amp;';
        entities['60'] = '&lt;';
        entities['62'] = '&gt;';
    } else if (useTable == 'HTML_ENTITIES') {
        // ascii decimals for better compatibility
      entities['38']  = '&amp;';
      entities['60']  = '&lt;';
      entities['62']  = '&gt;';
      entities['160'] = '&nbsp;';
      entities['161'] = '&iexcl;';
      entities['162'] = '&cent;';
      entities['163'] = '&pound;';
      entities['164'] = '&curren;';
      entities['165'] = '&yen;';
      entities['166'] = '&brvbar;';
      entities['167'] = '&sect;';
      entities['168'] = '&uml;';
      entities['169'] = '&copy;';
      entities['170'] = '&ordf;';
      entities['171'] = '&laquo;';
      entities['172'] = '&not;';
      entities['173'] = '&shy;';
      entities['174'] = '&reg;';
      entities['175'] = '&macr;';
      entities['176'] = '&deg;';
      entities['177'] = '&plusmn;';
      entities['178'] = '&sup2;';
      entities['179'] = '&sup3;';
      entities['180'] = '&acute;';
      entities['181'] = '&micro;';
      entities['182'] = '&para;';
      entities['183'] = '&middot;';
      entities['184'] = '&cedil;';
      entities['185'] = '&sup1;';
      entities['186'] = '&ordm;';
      entities['187'] = '&raquo;';
      entities['188'] = '&frac14;';
      entities['189'] = '&frac12;';
      entities['190'] = '&frac34;';
      entities['191'] = '&iquest;';
      entities['192'] = '&Agrave;';
      entities['193'] = '&Aacute;';
      entities['194'] = '&Acirc;';
      entities['195'] = '&Atilde;';
      entities['196'] = '&Auml;';
      entities['197'] = '&Aring;';
      entities['198'] = '&AElig;';
      entities['199'] = '&Ccedil;';
      entities['200'] = '&Egrave;';
      entities['201'] = '&Eacute;';
      entities['202'] = '&Ecirc;';
      entities['203'] = '&Euml;';
      entities['204'] = '&Igrave;';
      entities['205'] = '&Iacute;';
      entities['206'] = '&Icirc;';
      entities['207'] = '&Iuml;';
      entities['208'] = '&ETH;';
      entities['209'] = '&Ntilde;';
      entities['210'] = '&Ograve;';
      entities['211'] = '&Oacute;';
      entities['212'] = '&Ocirc;';
      entities['213'] = '&Otilde;';
      entities['214'] = '&Ouml;';
      entities['215'] = '&times;';
      entities['216'] = '&Oslash;';
      entities['217'] = '&Ugrave;';
      entities['218'] = '&Uacute;';
      entities['219'] = '&Ucirc;';
      entities['220'] = '&Uuml;';
      entities['221'] = '&Yacute;';
      entities['222'] = '&THORN;';
      entities['223'] = '&szlig;';
      entities['224'] = '&agrave;';
      entities['225'] = '&aacute;';
      entities['226'] = '&acirc;';
      entities['227'] = '&atilde;';
      entities['228'] = '&auml;';
      entities['229'] = '&aring;';
      entities['230'] = '&aelig;';
      entities['231'] = '&ccedil;';
      entities['232'] = '&egrave;';
      entities['233'] = '&eacute;';
      entities['234'] = '&ecirc;';
      entities['235'] = '&euml;';
      entities['236'] = '&igrave;';
      entities['237'] = '&iacute;';
      entities['238'] = '&icirc;';
      entities['239'] = '&iuml;';
      entities['240'] = '&eth;';
      entities['241'] = '&ntilde;';
      entities['242'] = '&ograve;';
      entities['243'] = '&oacute;';
      entities['244'] = '&ocirc;';
      entities['245'] = '&otilde;';
      entities['246'] = '&ouml;';
      entities['247'] = '&divide;';
      entities['248'] = '&oslash;';
      entities['249'] = '&ugrave;';
      entities['250'] = '&uacute;';
      entities['251'] = '&ucirc;';
      entities['252'] = '&uuml;';
      entities['253'] = '&yacute;';
      entities['254'] = '&thorn;';
      entities['255'] = '&yuml;';
    } else {
        throw Error("Table: "+useTable+' not supported');
        return false;
    }
    
    // ascii decimals to real symbols
    for (decimal in entities) {
        symbol = String.fromCharCode(decimal)
        histogram[symbol] = entities[decimal];
    }
    
    return histogram;
}

function htmlentities (string, quote_style) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: nobbler
    // +    tweaked by: Jack
    // +   bugfixed by: Onno Marsman
    // +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // -    depends on: get_html_translation_table
    // *     example 1: htmlentities('Kevin & van Zonneveld');
    // *     returns 1: 'Kevin &amp; van Zonneveld'
 
    var histogram = {}, symbol = '', tmp_str = '', entity = '';
    tmp_str = string.toString();
    
    if (false === (histogram = get_html_translation_table('HTML_ENTITIES', quote_style))) {
        return false;
    }
    
    for (symbol in histogram) {
        entity = histogram[symbol];
        tmp_str = tmp_str.split(symbol).join(entity);
    }
    
    return tmp_str;
}

function redirectToURL(url) {
	setTimeout(function() { window.location = url; }, 0);
}

/*
==================================================================
LTrim(string) : Returns a copy of a string without leading spaces.
==================================================================
*/
function LTrim(str)
/*
   PURPOSE: Remove leading blanks from our string.
   IN: str - the string we want to LTrim
*/
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {
      // We have a string with leading blank(s)...

      var j=0, i = s.length;

      // Iterate from the far left of string until we
      // don't have any more whitespace...
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;

      // Get the substring from the first non-whitespace
      // character to the end of the string...
      s = s.substring(j, i);
   }
   return s;
}

/*
==================================================================
RTrim(string) : Returns a copy of a string without trailing spaces.
==================================================================
*/
function RTrim(str)
/*
   PURPOSE: Remove trailing blanks from our string.
   IN: str - the string we want to RTrim

*/
{
   // We don't want to trip JUST spaces, but also tabs,
   // line feeds, etc.  Add anything else you want to
   // "trim" here in Whitespace
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      // We have a string with trailing blank(s)...

      var i = s.length - 1;       // Get length of string

      // Iterate from the far right of string until we
      // don't have any more whitespace...
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;


      // Get the substring from the front of the string to
      // where the last non-whitespace character is...
      s = s.substring(0, i+1);
   }

   return s;
}

/*
=============================================================
Trim(string) : Returns a copy of a string without leading or trailing spaces
=============================================================
*/
function Trim(str)
/*
   PURPOSE: Remove trailing and leading blanks from our string.
   IN: str - the string we want to Trim

   RETVAL: A Trimmed string!
*/
{
   return RTrim(LTrim(str));
}

function validate()
{


if(Trim(document.frm1.tarea.value)=="")
{


alert("is null");
}

else
{

alert("not null");
}

return false;

}


function validate_changePasswordForm()
{
	unsetIsError();

	validate_currentPass();
	validate_auPassword();
	validate_confirmauPassword();
	return checkError();

}

function validate_currentPass() {
	validate(1,'currentPass','currentPassErrorId','','PASSWORD',1,'','',0);
}

function validate_auPassword() {
	validate(1,'auPassword','auPasswordErrorId','','PASSWORD',1,6,'',0);
}

function validate_confirmauPassword() { 
	validate(1,'confirmauPassword','confirmauPasswordErrorId','','CONFIRMPASSWORD',0,'','auPassword',1);
}

