
function DeleteConfirm(val){
		window.open(val,'pop','directories=no,status=no,menubar=no,resizable=no,copyhistory=no,scrollbars=no,width=280,height=260,left=50,top=50')		
}
function CheckDis(num){
		if(num==1){
			document.filter.fromdate_day.disabled=false;
			document.filter.fromdate_month.disabled=false;
			document.filter.fromdate_year.disabled=false;
			document.filter.todate_day.disabled=false;
			document.filter.todate_month.disabled=false;
			document.filter.todate_year.disabled=false;
		}else{
			document.filter.fromdate_day.disabled=true;
			document.filter.fromdate_month.disabled=true;
			document.filter.fromdate_year.disabled=true;
			document.filter.todate_day.disabled=true;
			document.filter.todate_month.disabled=true;
			document.filter.todate_year.disabled=true;
		}

	}
function openMoreInfo(num){
	window.open('MoreInfo.asp?txt='+num,'pop','directories=no,status=no,menubar=no,resizable=no,copyhistory=no,scrollbars=yes,width=250,height=200,left=50,top=50');	
}

function ExportToExcel(num){
	window.open('ExportToExcel.asp?repType='+num,'pop','directories=no,status=no,menubar=no,resizable=yes,copyhistory=no,scrollbars=yes,width=250,height=200,left=50,top=50');		
}

function StatusChange(){
	document.frmUpdateAssets.status.value=1;
}

function myVoid() { }


function ConfirmUpdate(val){
if(document.frmUpdateAssets.status.value==1){
	var conf = confirm("You are about to exit this page.\nDo you wish to save the updates on this page?");
		if(conf){
		document.frmUpdateAssets.LinkToRedir.value = val;
		document.frmUpdateAssets.submit();
		}
}else{
	self.location.href = val;
	}
}

function UpdateChainHidden()
		{
			var cmb=document.filter.ParentGroup
			document.filter.hid_chain.value=cmb.options[cmb.selectedIndex].text
		}
		

function disableTargetFiled(obj)
	{
		if(obj.value != 0 )
		 {
			document.filter.TargetType.disabled = true
			document.filter.targetValue.value = ""
			document.filter.targetValue.disabled = true
		 }
		else
		 {
			document.filter.TargetType.disabled = false
			document.filter.targetValue.disabled = false
		 }
	}		

	
function ViewComponent(query) {
	window.open ("ViewImageDetails.asp?"+query,"comp",'directories=no,status=no,menubar=no,resizable=yes,copyhistory=no,scrollbars=yes,width=400,height=300,left=10,top=10');
}

function ViewGuide() {
	window.open ("userGuide.asp?","UserGuide",'directories=no,status=no,menubar=no,resizable=yes,copyhistory=no,scrollbars=yes,width=600,height=600,left=10,top=10');
}
	
	
	function ChangeParam(formObj){
			switch (formObj.options[formObj.selectedIndex].value){
				case "1":
					//disALL(4);
					document.filter.repType.value=1;
				break
				case "2":
					//disALL(0);
					document.filter.repType.value=2;
				break
				case "3":
					//disALL(1);
					document.filter.repType.value=3;
				break
				case "4" :
					//disALL(1);
					document.filter.repType.value=4;
				break	
				}
		}

function DownloadAsset(val){
	window.open (val,"comp",'directories=no,status=no,menubar=no,resizable=yes,copyhistory=no,scrollbars=no,width=450,height=350,left=10,top=10');
}

function checkContentReviewFrom(obj)
{
	var filedValue = obj.value
	if(filedValue != "")
	{
		if(isNaN(filedValue) == true) //is not number
		{
			alert("Please enter a numeric value")
			obj.focus();
			return false;
		}
		
		if((filedValue <=0) || (filedValue > 100))
		{
			alert("Please enter a number between 1 and 100")
			obj.focus();
			return false;	
		}
	}
	
}


function checkValidtyEmail(emailStr)
{
	if(!ValidtyEmail(emailStr))
	{
		alert("The email address you entered appears incomplete. \nPlease check and correct")
		return false;
	}
	return true;
}

function ValidtyEmail(emailStr)
{
	// function to check that the e-mail is valid
	var i
	var index
	var str
	
	if (emailStr == "")
	 {
		return false
	 }
	
	if (emailStr.length < 5)
	{
		return false
	}
		
	if ((emailStr.charAt(0) == '@') || (emailStr.charAt(0) == '.'))
	{
		return false
	}
	if ((emailStr.charAt(emailStr.length - 1) == '@') || (emailStr.charAt(emailStr.length - 2) == '.'))
	{
		return false
	}
	
	index = emailStr.indexOf('@')
	if (index == -1)
	{
		return false
	}
	if ((emailStr.charAt(index - 1) == '.') || (emailStr.charAt(index + 1) == '.'))	
	{
		return false
	}
	index++
	index = emailStr.indexOf('@', index)
	if (index != -1)
	{
		return false
	}
	
	index = emailStr.lastIndexOf('.')
	if (index == -1)
	{
		return false
	}
	//check if "." refer for email extension (.com,.co.uk)
	str = emailStr.substring(index);

	if((str.length < 2) || (str.length > 4))
	{
		return false
	}
		
	for (i = 0; i < emailStr.length; i++)
	{
		if ((emailStr.charAt(i) != '@') && (emailStr.charAt(i) != '.') && (emailStr.charAt(i) != '_') && (emailStr.charAt(i) != '-') && ((emailStr.charAt(i)<'A')||(emailStr.charAt(i)>'Z')) && ((emailStr.charAt(i)<'a')||(emailStr.charAt(i)>'z')) && ((emailStr.charAt(i)<'0')||(emailStr.charAt(i)>'9')))
		{
			return false
		}
	}
	
	return true

	
}

function OpenBrandMaterial(){
	document.location.href = document.brMat.brandMat.value;
}


	
	//-------------------------------------
	// Function:		LeapYear
	// Purpose:			Check if year is leap
	// Parameters:		input  - 	year	
	// return values:	true/false
	//-------------------------------------
	function LeapYear(intYear) 
	{
		if (intYear % 100 == 0) 
		{
			if (intYear % 400 == 0) 
			{ 
				return true; 
			}
		}
		else 
		{
			if ((intYear % 4) == 0) 
			{
				return true; 
			}
		}
		return false;
	}
	

	
	 function ValidateLogin(){
		if(!document.form1.UserLogin.value){
			alert("Please type your user name.");
			document.form1.UserLogin.focus();
			return false;
		}
		if(!document.form1.UserPassword.value){
			alert("Please type your password.");
			document.form1.UserPassword.focus();
			return false;
		}	
		if(document.form1.terms)
		{
			if(!document.form1.terms.checked){
				alert('Please read the Terms and Conditions and then CLICK on the I AGREE box prior to LOGON');
				return false;
			}
		}
	}
	

function sTerms(num)
		{
		window.open('terms.asp?num='+num,'','directories=no,status=no,menubar=no,resizable=yes,copyhistory=no,scrollbars=yes,width=586,height=500,left=100,top=45');
		}	
	
function terms(page){
		window.open(page,'pop','width=565,height=550,left=100,top=45,resizable=yes,scrollbars=yes')
	}
	
	
	function applyFilter(){
		alert('Apply Filter')
	}
	function UpdateChainHidden()
		{
			var cmb=document.filter.ParentGroup
			document.filter.hid_chain.value=cmb.options[cmb.selectedIndex].text
		}	
/* Modified by :Seema
   Modified on : 24-04-09
   Modified for : D#10859 Added following function. */				
function getFormConfirmation(formObj){
	if(mustSelectBrandForComplianceReport){
		if(document.filter.ParentGroup.options[document.filter.ParentGroup.selectedIndex].value == -1){
			alert('Please select Brand from the list');
			return false;
		}
	}else{
		return true;
	}
}
function ClearPaging(){
	document.filter.page.value=1;
	document.filter.lastPage.value=1;
}

function OpenWin1(sUrl,title,scrollBar,width,height){
			var statusBar = "directories=no,menubar=no,resizable=yes,copyhistory=no,scrollbars=" + scrollBar + ",top=100,left=100,width=" + width + ",height=" + height + ",status=no"
			window.open(sUrl, 'title', statusBar)
	  }	

function GoToPage(page)
{
 document.form1.JumpToPage.value = (page-1);
 document.form1.submit();
}

function doQuery()
{
 document.search.fromDate.value = document.search.fromMonth.value + "/" + document.search.fromDay.value + "/" + document.search.fromYear.value;
 document.search.toDate.value = document.search.toMonth.value + "/" + document.search.toDay.value + "/" + document.search.toYear.value;
 var dateExists = checkDate('from');
	if (!dateExists)
	{
		alert("From date do not Exist.");
	}
	else
	{
		dateExists = checkDate('to');
		if (!dateExists)
		{
			alert("To date do not Exist.");
		}
		else
		{
			document.search.submit();
		}
	}
}
function doCurrChainQuery()
{
 document.search.fromDate.value = document.search.fromMonth.value + "/" + document.search.fromDay.value + "/" + document.search.fromYear.value;
 document.search.toDate.value = document.search.toMonth.value + "/" + document.search.toDay.value + "/" + document.search.toYear.value;
 if(document.search.property.value != "")
 {
	inputValue = document.search.property.value;
	inputValue = inputValue.substr(0,2);
	if(inputValue == '<%=Session("CHAIN_CODE")%>')
	{
		document.search.submit();
	}
	else
	{
		alert("Not a valid Hotel ODD code for current chain");
	}
 }
 else
 {
	var dateExists = checkDate('from');
	if (!dateExists)
	{
		alert("From date do not Exist.");
	}
	else
	{
		dateExists = checkDate('to');
		if (!dateExists)
		{
			alert("To date do not Exist.");
		}
		else
		{
			document.search.submit();
		}
	}
 }
}

var monthLength = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
function checkDate(name)
{
	var x = document.forms[0].elements;
	var day = parseInt(x[name+"Day"].options[x[name+"Day"].selectedIndex].value);
	var month = parseInt(x[name+"Month"].options[x[name+"Month"].selectedIndex].value);
	var year = parseInt(x[name+"Year"].options[x[name+"Year"].selectedIndex].value);

	if (!day || !month || !year)
		return false;

	if (year/4 == parseInt(year/4))
		monthLength[1] = 29;

	if (day > monthLength[month-1])
		return false;

	monthLength[1] = 28;

	var now = new Date();
	now = now.getTime(); //NN3

	var dateToCheck = new Date();
	dateToCheck.setYear(year);
	dateToCheck.setMonth(month-1);
	dateToCheck.setDate(day);
	var checkDate = dateToCheck.getTime();

	var futureDate = (now < checkDate);
	var pastDate = (now > checkDate);

	return true;
}

function Export2Excel(caption)
{
	document.frames.ifExcellContent.document.execCommand("saveAs",true, caption);
}

//calling an asp poage by ajax
function getFromDB(iurl)
	{
	// Code for Mozilla, etc.
		if (window.XMLHttpRequest) {
			xmlhttp = new XMLHttpRequest();
			xmlhttp.open("GET", iurl, false);
			xmlhttp.send(null);
		} else if (window.ActiveXObject) {
		// Code for IE
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			if (xmlhttp) {
				xmlhttp.open("GET", iurl, false);
				xmlhttp.send();
			}
		}
		
		return xmlhttp.responseText;
	}

function checkForm(formObj){
			if((formObj.uID.value)&&(formObj.uPwrd.value)){
				return true;
			}else{
				alert('Please enter User Name and Password');
				return false;
			}
		}
		
		
function DisplayMessage(fieldName,par){
	var url = 'ExportToExcel.asp';
	var params = par +'&now='+Math.random();
	var ajax = new Ajax.Updater({success: fieldName},url,{method: 'get', parameters: params, onFailure: reportError});
	}
	
	function reportError(request) {
	alert('Error');
	}

function popup1(val){window.open(val,'flash','width=625,height=340,left=100,top=45,resizable=no,scrollbars=no');}




function iFrameHeight() { 
	if(document.getElementById && !(document.all)) { 
		h = document.getElementById('iframename').contentDocument.body.scrollHeight; 
		document.getElementById('iframename').style.height = h; 
	} 
else if(document.all) { 
		h = document.frames('iframename').document.body.scrollHeight; 
		document.all.iframename.style.height = h; 
	} 
}

	function FormatFloat(sNum,iDigitsAfterPoint){
			var iPointIndex;		
			
			iPointIndex = sNum.toString(10).indexOf(".");
			if(iPointIndex > -1){
				if(iDigitsAfterPoint > 0){
					return sNum.toString(10).substr(0,iPointIndex) + sNum.toString(10).substr(iPointIndex, iDigitsAfterPoint + 1)
				}else{
					return sNum.toString(10).substr(0,iPointIndex);
				}
			}
					
			return sNum.toString(10);
		}
	var setW,setH;
	var resizedMatrixH;
	var resizedMatrixW;

	function SetCropFrame(wid,hei,oWid,oHei,derTypeId,formatToUse,compTypeSign,compTypeID){
		setW = window.frames[0].document.getElementById('testImage').width;
		setH = window.frames[0].document.getElementById('testImage').height;
	var imgAspectRatio;
	var oCoefW=oWid/setW;
	var oCoefH=oHei/setH;
	resizedMatrixW = FormatFloat(wid / oCoefH,0);
	resizedMatrixH = FormatFloat(hei / oCoefH,0);
	document.getElementById('origHeight').value = setH;
	document.getElementById('origWidth').value = setW;
	var curImage = window.frames[0].document.getElementById('testImage').src;
	var arrCurImage = curImage.split('?');
	var compName = arrCurImage[0].substring(arrCurImage[0].length-6);
	compName = compName.substring(0,2);
	var imageToUse = arrCurImage[0].substring(0,arrCurImage[0].length-7)+ formatToUse + compName + '.jpg?' + arrCurImage[1];
	var curPage = document.getElementById('iframename').src.split('?') [0];
	document.getElementById('iframename').src = curPage + '?compTypeID='+compTypeID+'&compName='+compName+'&imageToShow=' + escape(imageToUse)+ '&derTypeId=' + derTypeId + '&cX=' + resizedMatrixW + '&cY=' + resizedMatrixH + '&t=' + escape(new Date())+'&oCoefH=' + FormatFloat(oCoefH,10) + '&oCoefW=' + FormatFloat(oCoefW,10) + '&derW=' + wid + '&derH=' + hei+'&compTypeSign='+compTypeSign;
	}

	
function getCropImage(){
var cLeft = document.getElementById('cx1').value;
var cTop = document.getElementById('cy1').value;
var cWid = document.getElementById('cx2').value;
var cHei = document.getElementById('cy2').value;
var origH = document.getElementById('origHeight').value;
var origW = document.getElementById('origWidth').value;
var correctSizeW = document.getElementById('cWidth').value;
var correctSizeH = document.getElementById('cHeight').value;
var compID = document.getElementById('compID').value;
var compTypeSign = document.getElementById('compTypeSign').value;
var compName = document.getElementById('compName').value;
var compTypeID = document.getElementById('compTypeID').value;
cWid = cWid - cLeft;
cHei = cHei - cTop;
var fLeft,fTop,fWidth,fHeight;
var sTSParamsCrop;
		if(parseInt(cLeft) + parseInt(cWid) > parseInt(origW)){
			cWid = parseInt(origW) - parseInt(cLeft);			
		}
		if(parseInt(cTop) + parseInt(cHei) > parseInt(origH)){
			cHei = parseInt(origH) - parseInt(cTop);
		}
		fLeft = FormatFloat(cLeft / origH, 2);
		fTop = FormatFloat(cTop / origH, 2);
		fWidth = FormatFloat(cWid / origH, 2);
		fHeight =  FormatFloat(cHei / origH, 2);
var sTSParamsCrop = "rgn=" + fLeft + "," + fTop + "," + fWidth + "," + fHeight + "&wid=" + correctSizeW + "&hei=" + correctSizeH;
	window.open('CropAssetResponse.asp?compTypeID='+compTypeID+'&compName='+compName+'&compTypeSign='+compTypeSign+'&compID='+compID+'&imageSrc='+escape(window.frames[0].document.getElementById('testImage').src.split('?')[0] +'?'+sTSParamsCrop+'&cvt=jpg'),'cropW','width=200,height=150');
}


function showTheImage(imagePath){
	document.getElementById('previewImage').innerHTML = unescape(imagePath);
}
function setUploadArguments(typeID,typeSign,compID,crossRefCode,reqW,reqH,dTypeId){
	document.getElementById('uploadArgs').value = 'ReplaceAssetType.asp?assetTypeID='+typeID+'&assetTypeSign='+typeSign+'&compID='+compID+'&crossRefCode='+crossRefCode+'&formatId=2&compGroupID=1&reqW='+reqW+'&reqH='+reqH+'&dTypeId='+dTypeId;

}
function doUpload(){
	var pageArgs = document.getElementById('uploadArgs').value;
	if(pageArgs){
		OpenWin1(pageArgs,'Replace Asset','no','480','160');
	}else{
		alert('Please select an image to upload/replace')
	}
}
		

		
		
/**
*
*  Base64 encode / decode
*  http://www.webtoolkit.info/
*
**/
 
var Base64 = {
 
	// private property
	_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
 
	// public method for encoding
	encode : function (input) {
		var output = "";
		var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
		var i = 0;
 
		input = Base64._utf8_encode(input);
 
		while (i < input.length) {
 
			chr1 = input.charCodeAt(i++);
			chr2 = input.charCodeAt(i++);
			chr3 = input.charCodeAt(i++);
 
			enc1 = chr1 >> 2;
			enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
			enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
			enc4 = chr3 & 63;
 
			if (isNaN(chr2)) {
				enc3 = enc4 = 64;
			} else if (isNaN(chr3)) {
				enc4 = 64;
			}
 
			output = output +
			this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
			this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
 
		}
 
		return output;
	},
 
	// public method for decoding
	decode : function (input) {
		var output = "";
		var chr1, chr2, chr3;
		var enc1, enc2, enc3, enc4;
		var i = 0;
 
		input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
 
		while (i < input.length) {
 
			enc1 = this._keyStr.indexOf(input.charAt(i++));
			enc2 = this._keyStr.indexOf(input.charAt(i++));
			enc3 = this._keyStr.indexOf(input.charAt(i++));
			enc4 = this._keyStr.indexOf(input.charAt(i++));
 
			chr1 = (enc1 << 2) | (enc2 >> 4);
			chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
			chr3 = ((enc3 & 3) << 6) | enc4;
 
			output = output + String.fromCharCode(chr1);
 
			if (enc3 != 64) {
				output = output + String.fromCharCode(chr2);
			}
			if (enc4 != 64) {
				output = output + String.fromCharCode(chr3);
			}
 
		}
 
		output = Base64._utf8_decode(output);
 
		return output;
 
	},
 
	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	},
 
	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}
 
		return string;
	}
 
}		