/////////////// DISPLAYING SELECTED PRODUCT REGION FROM COOKIES ////////////
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 '';
}

//// READING first level cookie
var strCookie1 = readCookie('igcnregion');
var strCookie2;
var blnCookiesAreSet = true;

if (strCookie1 != ''){
   //// READING second level cookie   
   strCookie2 = readCookie(strCookie1);
   if (strCookie2 != '' && document.getElementById('divProductRegion') != null ){
     document.getElementById('divProductRegion').innerHTML = strCookie2;
   }else{
     blnCookiesAreSet = false;
   }
}else{
   blnCookiesAreSet = false;
}

//// Redirect to VictaulicWorldwide page if region cookies are not set
var strCheckURL = document.URL;
if (strCheckURL.indexOf('/inContext/_admin/') == -1 && blnCookiesAreSet != true){
	window.document.location = '/';
}
////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////
////////////// DELETE igcnregion COOKIE ////////////////////////////////////////
function deleteCookie(){
	setCookie(readCookie('igcnregion'),'',-1);
	setCookie('igcnregion','',-1);
	
	location.href = '/';
}
function setCookie(name,value,duration){
	//var cookiestring=name+"=;expires="+getExpiryDate(duration);
	var cookiestring=name+'=; expires=Thu, 2 Aug 2001 20:47:11 UTC; path=/';
	document.cookie=cookiestring;
}
/*
function getExpiryDate(nodays){
	var UTCstring;
	Today = new Date();
	nomilli=Date.parse(Today);
	Today.setTime(nomilli+nodays*24*60*60*1000);
	UTCstring = Today.toUTCString();
	return UTCstring;
}
*/
////////////////////////////////////////////////////////////////////////////



//////// ----- GLOBAL VARIABLE ----- /////////
///// assetID=669 - Victaulic

var gStrAppend = 'inCtx9';
var gStrUrl = 'http://www.victaulic.com/content/search.htm'
var gStrAlert = 'Please enter a keyword to search.';

var URLstr=document.URL
var URLpos
//alert (URLstr);

if (URLstr.search('/ch/')>=0 || URLstr.search('site_id=2')>=0) { gStrUrl = 'http://www.victaulic.com/content/ch/search.htm';}
else if (URLstr.search('/es/')>=0 || URLstr.search('site_id=3')>=0) { gStrUrl = 'http://www.victaulic.com/content/es/search.htm';}
else if (URLstr.search('/de/')>=0 || URLstr.search('site_id=4')>=0) { gStrUrl = 'http://www.victaulic.com/content/de/search.htm';}
else if (URLstr.search('/ca/')>=0 || URLstr.search('site_id=5')>=0) { gStrUrl = 'http://www.victaulic.com/content/ca/search.htm';}
else if (URLstr.search('/la/')>=0 || URLstr.search('site_id=6')>=0) { gStrUrl = 'http://www.victaulic.com/content/la/search.htm';}
else if (URLstr.search('/it/')>=0 || URLstr.search('site_id=7')>=0) { gStrUrl = 'http://www.victaulic.com/content/it/search.htm';}
else if (URLstr.search('/fr/')>=0 || URLstr.search('site_id=8')>=0) { gStrUrl = 'http://www.victaulic.com/content/fr/search.htm';}
else if (URLstr.search('/kr/')>=0 || URLstr.search('site_id=9')>=0) { gStrUrl = 'http://www.victaulic.com/content/kr/search.htm';}
else if (URLstr.search('/pl/')>=0 || URLstr.search('site_id=10')>=0) { gStrUrl = 'http://www.victaulic.com/content/pl/search.htm';}
else if (URLstr.search('/nl/')>=0 || URLstr.search('site_id=11')>=0) { gStrUrl = 'http://www.victaulic.com/content/nl/search.htm';}
else if (URLstr.search('/br/')>=0 || URLstr.search('site_id=13')>=0) { gStrUrl = 'http://www.victaulic.com/content/br/search.htm';}
//alert (URLstr.search('/nl/);


//////// ----- GLOBAL VARIABLE ----- /////////


function siteSearch() {
	var term = document.getElementById("term").value ;
	if (term == '') { 
		alert(gStrAlert);
		return false ; 
	}else{
		var search_href = gStrUrl + '?' + gStrAppend + 'txtKeyword=' + term + '&' + gStrAppend + 'cmdKeywordSearch=search&' + gStrAppend + 'txtMode=site';
		//alert(search_href);
		window.location.href = search_href ;
	}
	window.event.cancelBubble = true;
	window.event.returnValue = false;
}


function onKeyPress(e) {

	NS4 = (document.layers)? true:false
	IE4 = (document.all)? true:false
	docom = (document.getElementById) ? true:false

	var keycode;
	var strName = navigator.appName;

	if (NS4) keycode = e.which 
	else if (IE4) keycode = window.event.keyCode
	else if (docom)	keycode = e.keyCode

	if (keycode == 13) {
		if((IE4)&&(navigator.platform=='MacPPC')){
			document.frm.HiddenClick.value = '';
			//strName = strName + ' : ' + navigator.platform
			alert(strName)
		}else{
			siteSearch()
			window.event.cancelBubble = true;
			window.event.returnValue = false;
		}
	}
}




////////////////////////////////////////////////
////////// ----- REGULAR SEARCH ----- //////////
//--------------------------------------------//

function siteSearchMain() {
	var term = document.getElementById(gStrAppend + "txtKeyword").value ;
	var qu = '' ;
	if (term == '') { 
		alert(gStrAlert);
		event.returnValue=false;
		return false ; 
	}else{
		cmsForm.action = gStrUrl;
		cmsForm.submit();
		event.returnValue=false;
	}
}

function onKeyPressMain(e) {

	NS4 = (document.layers)? true:false
	IE4 = (document.all)? true:false
	docom = (document.getElementById) ? true:false

	var keycode;
	var strName = navigator.appName;

	if (NS4) keycode = e.which 
	else if (IE4) keycode = window.event.keyCode
	else if (docom)	keycode = e.keyCode

	if (keycode == 13) {
		if((IE4)&&(navigator.platform=='MacPPC')){
			document.frm.HiddenClick.value = '';
			//strName = strName + ' : ' + navigator.platform
			alert(strName)
		}else{
			siteSearchMain()
		}
	}
}

//--------------------------------------------//
////////// ----- REGULAR SEARCH ----- //////////
////////////////////////////////////////////////





////////////////////////////////////////////////
////////// ----- ADVANCE SEARCH ----- //////////
//--------------------------------------------//

function setDates(fdate, edate) {
	var start_dt = document.getElementById(gStrAppend + 'txtStartDate') ;
	var end_dt = document.getElementById(gStrAppend + 'txtEndDate');
	start_dt.value = fdate ;
	end_dt.value = edate ;
}
	
function calcDate(rng) {
	var x = new Date()
	var y = new Date()
	x.setDate(x.getDate() - 1)

	var oRange = document.getElementById('range');
	if (rng == '7') {
		y.setDate(x.getDate() - 7)
	} else if (rng == '30') {
		y.setMonth(x.getMonth() - 1)
	} else if (rng == '90') {
		y.setMonth(x.getMonth() - 3)
	} else if (rng == '365') {
		y.setYear(x.getFullYear() - 1)
	}
	if (rng == 'B' || rng == 'D') {
		setDates('','') ;
	} else {
		fdate = parseInt(y.getMonth()+1) + '/' + y.getDate() + '/' + y.getFullYear()
		edate = parseInt(x.getMonth()+1) + '/' + x.getDate() + '/' + x.getFullYear()
		setDates(fdate, edate)
	}
}

//--------------------------------------------//
////////// ----- ADVANCE SEARCH ----- //////////
////////////////////////////////////////////////



function onKeyPress1(e) {

	NS4 = (document.layers)? true:false
	IE4 = (document.all)? true:false
	docom = (document.getElementById) ? true:false

	var keycode;
	var strName = navigator.appName;

	if (NS4) keycode = e.which 
	else if (IE4) keycode = window.event.keyCode
	else if (docom)	keycode = e.keyCode

	if (keycode == 13) {
		/*if((IE4)&&(navigator.platform=='MacPPC')){
			document.frm.HiddenClick.value = '';
			//strName = strName + ' : ' + navigator.platform
			alert(strName)
		}else{*/
			siteSearchOne()
			window.event.cancelBubble = true;
			window.event.returnValue = false;
		//}
	}
}

var gStrUrl1 = 'search.asp'

function siteSearchOne() {
	//alert("here")
	var oObj = document.getElementById("SiteSearchUrl");
	if(oObj != null){
		//alert(document.getElementById("SiteSearchUrl").value);
		gStrUrl1 = document.getElementById("SiteSearchUrl").value;
	}

	var term = document.getElementById("q").value ;
	var client = document.getElementById("client").value ;
	var proxystylesheet = document.getElementById("proxystylesheet").value ;
	var output = document.getElementById("output").value ;
	var site = document.getElementById("site").value ;
	
	
	
	if (term == '') { 
		alert(gStrAlert);
		return false ; 
	}else{
		var search_href = '/' + gStrUrl1 + '?' + 'client=' + client + '&proxystylesheet=' + proxystylesheet + '&output=' + output + '&site=' + site + '&q=' + term + '&btnSearch=Search';
		//alert(search_href);
		window.location.href = search_href ;
	}
	window.event.cancelBubble = true;
	window.event.returnValue = false;
}

























