﻿//function for Checking the Empty Value
function isEmptyCheck(strValue, strErrMsg)
{
	if (Trim(strValue.value)=="")
	{
		alert(strErrMsg);
		//strValue.focus();
		return false;
	}
//	return true;
}


//Creates new HTML window with the String passed as Display DAta
function CreateNewWindow(strData)
{
	var abc = window.open("", "wndNewsDetail" , "fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no,directories=no,location=no,width=300,height=200,left=200,top=200");
    var frmPopup = "<html><Head><Title>How to Select Categories for Joining</Title>";
    frmPopup = frmPopup + "<LINK href=\"../includes/stylesheet.css\" type=\"text/css\" rel=stylesheet\>";
    frmPopup = frmPopup + "\</Head\>\<Body\"\><p class='tengrey'\>"
	frmPopup = frmPopup + strData + " \</BODY\></HTML\>";
	abc.document.write(frmPopup)
}


function chkLength(strValue, strLength, strErrMsg)
{

	//alert(strValue.value.length);
	if (Trim(strValue.value).length==0)
	{
		alert("Please Enter a value");
		strValue.focus();
		return false;
	}
	

	if (Trim(strValue.value).length<strLength)
	{
		alert(strErrMsg);
		strValue.focus();
		return false;
	}
	//alert(Trim(strValue))
	if (isNaN(Trim(strValue.value))==true) // || Trim(strValue) == null)
	{
		alert("Please Enter a numeric value!!");
		strValue.focus();
		return false;	
	}


	return true;
}

//function for Checking the Deletion Confirmation
function ConfirmDelete(strValueToDelete)
{
			return confirm("Are you sure you want to delete this entry ?");
}
//to check to add confirmation
function ConfirmAction(strMessage)
{
	//alert('sss');
	if(strMessage != "")
		return confirm(strMessage);
	else
		return confirm("Are you sure you want to do this?");
	
}

function chkValues(str1, str2 , strMsg)
{
	if (str1!=str2)
	{
		alert(strMsg);
		return false; 
	}
	return true;
}


//Function for chking the Extension of the image is Valid
function IsImageValid(ValueToChk)
{
//alert(ValueToChk.value)
	if (ValueToChk.value!="")
	{
		var strExtension=ValueToChk.value.substring(ValueToChk.value.length,ValueToChk.value.length-3)
		switch(strExtension)
		{
			case "jpg":
				return true;
				break;
			case "JPG":
				return true;
				break;
			case "gif":
				return true;
				break;
			case "GIF":
				return true;
				break;
			//case "bmp":
			//	return true;
			//	break;
			//case "BMP":
			//	return true;
			//	break;
			default:
				MessageInvalidImage()			
				return false;
		}
	}
	return true;	
}


function MessageInvalidImage()
{
	//alert("Invalid Image Extension")
	alert("Please select an image of type '.gif' or '.jpg'");
}


//function for Opening the New Window
function OpenWindow(strPath)
{
	window.open(strPath, '', 'fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=no,directories=no,location=no,width=800,height=600,Left='+(screen.width-800)/2+',top='+(screen.height-600)/2 );
}

function openWindow(strPath, ht, wt)
{	
	window.open(strPath, 'Window', "fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no,directories=no,location=no,width=559,height=140,Left=(screen.width-" + wt + ")/2 ,top=(screen.height-" + ht + ")/2");
}


//function for Opening the New Window
function OpenWindowGuidelines(strPath)
{
	window.open(strPath, '', 'fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=no,directories=no,location=no,width=640,height=640,Left='+(screen.width-640)/2+',top='+(screen.height-640)/2 );
}


//Email Validation
function isEmailValid(str) 
{
	checkEmail = str.value
//this logic allows 2,3 and 4 character domain names
	if ((checkEmail.indexOf('@') < 0) || ((checkEmail.charAt(checkEmail.length-5) != '.')&&
										  (checkEmail.charAt(checkEmail.length-4) != '.') && 
										  (checkEmail.charAt(checkEmail.length-3) != '.'))) 
	{
		alert("Please Enter a Valid Email Address");
		str.focus();
		return false;
	} 
return true;
}

function ShowWindowWhileUploading()
{
	//window.showModalDialog("http://www.hotmail.com","","center:yes;resizable:no;dialogHeight:150px")
	//alert("CALLED")
	window.open("../includes/Upload.htm" ,"", "fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no,directories=no,location=no,width=500,height=200,left=280,top=180")
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~Chks the Entered value is Number or not..~~~~~~~~~~
//CREATED BY: Bhavin
//Version: 1.0
//Created Date: 15-01-2003
//Modified Date:
//Modified By:
function validateNumber(ControlToChk)
{
	if (isNaN(ControlToChk.value))
	{
		alert("Please Enter Numeric Value with No Spaces");
		ControlToChk.focus();
		return false;	
	}
return true;
}


//~~~~~~~~~~~~~~~~~~~~~~DATE VALIDATION CODE~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//CREATED BY: Bhavin
//Version: 1.0
//Created Date: 15-01-2003
//Modified Date:
//Modified By:
function checkdate(objName) 
{
	var datefield = objName;
	
	if (datefield.value=="")
	{
		alert("Enter Date!!");
		return false;
	}

	
	if (chkdate(objName) == false) 
	{
		datefield.select();
		alert("Invalid Date. Please try again.");
		datefield.focus();
		return false;
	}
	else 
	{
		//alert(chkdate(objName))
		return true;
	}
	
	return;
}


function chkdate(objName) 
{
	var strDatestyle = "US"; //United States date style
	//var strDatestyle = "EU";  //European date style
	var strDate;
	var strDateArray;
	var strDay;
	var strMonth;
	var strYear;
	var intday;
	var intMonth;
	var intYear;
	var booFound = false;
	var datefield = objName;
	var strSeparatorArray = new Array("-"," ","/",".");
	var intElementNr;
	var err = 0;
	/*
	var strMonthArray = new Array(12);
	strMonthArray[0] = "Jan";
	strMonthArray[1] = "Feb";
	strMonthArray[2] = "Mar";
	strMonthArray[3] = "Apr";
	strMonthArray[4] = "May";
	strMonthArray[5] = "Jun";
	strMonthArray[6] = "Jul";
	strMonthArray[7] = "Aug";
	strMonthArray[8] = "Sep";
	strMonthArray[9] = "Oct";
	strMonthArray[10] = "Nov";
	strMonthArray[11] = "Dec";
	*/
	strDate = datefield.value;

	if (strDate.length < 1) 
	{
		return true;
	}	
	
	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) 
	{
		if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) 
		{
			strDateArray = strDate.split(strSeparatorArray[intElementNr]);
			if (strDateArray.length != 3) 
			{
				err = 1;
				return false;
			}
			else 
			{
				strDay = strDateArray[0];
				strMonth = strDateArray[1];
				strYear = strDateArray[2];
			}
		booFound = true;
		}
	}
	
	if (booFound == false) 
	{
		if (strDate.length>5) 
		{
			strDay = strDate.substr(0, 2);
			strMonth = strDate.substr(2, 2);
			strYear = strDate.substr(4);
		}
	}

		
	if (strYear.length == 2) 
	{
		strYear = '20' + strYear;
	}
	
	// US style
	if (strDatestyle == "US") 
	{
		strTemp = strDay;
		strDay = strMonth;
		strMonth = strTemp;
	}

intday = parseInt(strDay, 10);

	if (isNaN(intday)) 
	{
		err = 2;
		return false;
	}
	
	if(intday == "00")
	{
	  alert("Invalid DATE");
	}

intMonth = parseInt(strMonth, 10);

	if (isNaN(intMonth)) 
	{
		for (i = 0;i<12;i++) 
		{
			/*if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) 
			{
				intMonth = i+1;
				strMonth = strMonthArray[i];
				i = 12;
			}*/
		}

		if (isNaN(intMonth)) 
		{
			err = 3;
			return false;
		}
	}

intYear = parseInt(strYear, 10);
	if (isNaN(intYear)) 
	{
		err = 4;
		return false;
	}

	if (intMonth>12 || intMonth<1) 
	{
		err = 5;
		return false;
	}

	if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth 

== 12) && (intday > 31 || intday < 1)) 
	{
		err = 6;
		return false;
	}

	if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) 
	{
		err = 7;
		return false;
	}

	if (intMonth == 2) 
	{
		if (intday < 1) 
		{
			err = 8;
			return false;
		}
		if (LeapYear(intYear) == true) 
		{
			if (intday > 29) 
			{
				err = 9;
				return false;
			}
		}	
		else 
		{
			if (intday > 28) 
			{
				err = 10;
				return false;
			}
		}
	}

	/*if (strDatestyle == "US") 
	{
		datefield.value = strMonthArray[intMonth-1] + " " + intday+" " + strYear;
	}
	else
	{
		datefield.value = intday + " " + strMonthArray[intMonth-1] + " " + strYear;
	}*/
	
return true;
}

function LeapYear(intYear) 
{
	if (intYear % 100 == 0) 
	{
		if (intYear % 400 == 0) 
		{ 
			return true; 
		}
	}
	else 
	{
		if ((intYear % 4) == 0) 
		{ 
			return true; 
		}
	}

return false;
}

function doDateCheck(from, to)
{
	if (Date.parse(from.value) <= Date.parse(to.value))
	{
		//alert("The dates are valid.");
		return true;
	}
	else
	{
		if (from.value == "" || to.value == "") 
		{
			alert("Both dates must be entered.");
			return false;
		}
		else
		{
			alert("Closing Date should be the same or after the Opening Date.");
			return false;
		}
	}
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~DATE VALIDATION CODE ENDS~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Value Trimming Function ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
function Trim(strValue)
{
   	return LTrim(RTrim(strValue));
}

function LTrim(strValue)
{
   	var LTRIMrgExp = /^\s */;
   	return strValue.replace(LTRIMrgExp, '');
}

function RTrim(strValue)
{
	var RTRIMrgExp = /\s *$/;
	return strValue.replace(RTRIMrgExp, '');
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ End of Value Trimming Function ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`


//pop up window to add a link for my inner circle
function setInnerCircle(memberID, linkedMemberID, action){
	if(memberID == linkedMemberID){
		window.alert("You cannot add your own page");
		return;
	}
	var url = "../includes/setInnerCircle.php?mid=" + memberID + "&linkid=" + linkedMemberID + "&action=" + action;
	window.open(url,'','width=825, height=600, resizable=yes, scrollbars=yes');
}

//My InnerCircle add button mouse over  
function btnAddOver(element){
	
	element.src = "../images/innerCircle/myInnerCircleBtnAddOver.gif";

}
//My InnerCircle add button mouse out
function btnAddOut(element){

	element.src = "../images/innerCircle/myInnerCircleBtnAdd.gif";

}


/** BEGIN : File validation - file name cannot contain special characters */


function validateFile(fileNameExt){

	//window.alert("file : " + fileNameExt);
	//window.alert("File selected");
	//var fileNameExt = document.getElementById("fileUpload").value; //file name with extension.
	var userAgent = window.navigator.userAgent;
	//window.alert("user agent : " + userAgent);
	var win = (userAgent.indexOf("Win") != -1);
				
	var arrFilePaths;
				
	if(win){
		//window.alert("you are in windows environment");
		//if(fileNameExt.indexOf("\\") != -1){ //windows environment
			arrFilePaths = fileNameExt.split("\\");
			checkSpecialChars(arrFilePaths);
		//}
	}
	else{ //file name will contain "/" as a folder separator
		//window.alert("you are not in windows environment");
					
		//if(fileNameExt.indexOf("\/") != -1){ //not windows environment
			arrFilePaths = fileNameExt.split("\/");
			checkSpecialChars(arrFilePaths);						
		//}
					
	}
				
}//end validateFile()
			
function checkSpecialChars(arrFilePaths){
				
	var fileName;
	var file;
	var pattern = /[^ a-zA-Z0-9-_]/; ///\W/; // matches any non-word (non-alphanumeric) character. equivalent to [^A-Za-z0-9_]
	//var regexp = new RegExp(pattern); 
	//var arrSpecialChars = null;
	var found = "";

	//fileName = arrFilePaths.pop();	
	fileName = arrFilePaths[arrFilePaths.length - 1]; //get last item (base file name)
	//window.alert("file name : " + fileName);
	arrFileNames = fileName.split(".");
	var test = 0;
	var ext;
	for(var j=0;j<arrFileNames.length;j++) {
		ext = arrFileNames[j];	
	}
	
	//if(ext!='jpg' && ext!='jpeg' && ext!='JPG' && ext!='JPEG') {
	//	window.alert("Invalid file format. Files must be .jpg or .jpeg format.");
	//	return false;
	//}
	//else{
		//file = arrFileNames.shift();
		file = arrFileNames[0]; //get first item (strip file extension)
		//window.alert("file : " + file);
							
		//window.alert("special char at : " + file.search(regexp));
							
		if(file.search(pattern) != -1){ //if file name contains special character(s) then alert user
					
		//arrSpecialChars = file.match(pattern);
		//window.alert("length : " + arrSpecialChars.length);
			for(var i=0; i<file.length; i++){
				str = file.charAt(i);
				//if(str != " "){
					if(str.match(pattern) != null){
						found += str.match(pattern) + ", ";
					}
				//}
			}
		//if(found != ""){
			window.alert("Invalid file format \nFile name cannot contain : " + found.substring(0, (found.length - 2)));
			//window.alert("Invalid file format \nFile name cannot contain : " + found);
			return false;
		//}
		}
		else{
			return true;
		}
		/*
		if(arrSpecialChars != null){
			var msgAlert = "Invalid file format \nFile name cannot contain : ";
						
			for(var i=0; i<arrSpecialChars.length; i++){
				str = arrSpecialChars.charAt(i);
				if(str.match(pattern) != null){
					msgAlert += str.match(pattern) + ", ";
				}
			}
						
			window.alert(msgAlert.substring(0, (msgAlert.length - 2)));
			return false;
		
		}
		else{
			//window.alert("Valid file");
			return true;
		}
		*/
	//}
}//end checkSpecialChars()
			

/** END : File validation */


/** BEGIN : Home page scrolling announcement - scroll text navigation menu added on 10-05-2006 */

			var pTimer;
			var height = 100; //add 100 since margin-top is 100px
			var arrMenuHeights = new Array();
			
			function setHeight(){

				var result = "";
				arrMenuHeights[0] = height + 10;
				for(var j=0; j<3; j++){
					
					var divMenu = document.getElementById("menu_" + j);
					//arrMenuHeights[j] = divMenu.offsetHeight;
					//arrMenuHeights[j] = height;
					height += divMenu.offsetHeight + 10; //add 10 since every menu has padding-bottom of 10px
					arrMenuHeights[j+1] = height;
					
				}
				var arrTemp = new Array();
				for(var m=0; m<arrMenuHeights.length; m++){
					if(arrMenuHeights[m] > 100){
						
					}
					arrTemp[m] = arrMenuHeights[m];
				}
				
				for(var k=0; k<2; k++){
					result += " [" + k + "] : " + arrMenuHeights[k];
				}
							
				//var lblMsg = document.getElementById("lblMsg");
				//lblMsg.value = result;
			}
			
			var i = 0;
			//var interval = 50;
			var index = 0;
			function move(){
				//var lblMsg = document.getElementById("lblMsg");
				var interval = 100;
				
				var divNav = document.getElementById("nav");
				if(i == -height){
					//lblMsg.value = " i: " + i + " height: " + height;
					i = 0;
				}
				//for(var k=0; k<arrMenuHeights.length; k++){
				var pos = ((arrMenuHeights[index] * -1) - 48);
				//if(pos == i || i == -92){
				//if(pos == i){
				var posPause = i % 105; // pause every 100px
				if(pos == i){ // || posPause == 0){
					interval += 4000;
					//lblMsg.value = "index: " + index + " pos: " + pos + " i: " + i;
					index++;
				}
				if(index == (arrMenuHeights.length - 1)){
					index = 0;
				}
				//}
				i--;
				divNav.style.top = i + "px";
				pTimer = setTimeout("move()", interval);
			}
			
			function pauseScroll(){
				clearTimeout(pTimer);
			}
			

/** END : Home page scrolling announcement - scroll text navigation menu added on 10-05-2006 */

/** BEGIN: myaccount upgrade step1 popup */

function notifyReload(win){
	if(win.closed == true){
		//window.alert("opened window has beend closed");
		window.self.location.reload();
		clearTimeout(timerID);
	}
	else{
		timerID = setTimeout("notifyReload(win)", 1000);
	}
}
				
function popUpgradeStep1(){
					
	var width = window.innerWidth;
	var height = window.innerHeight;
	//window.alert("w: " + width + " h: " + height);
					
	win = window.open('myaccount_upgrade_step1.php', 'UpgradeStep1', 'width=' + width + ', height=' + height + ', scrollbars=yes, resizable=yes, toolbar=yes, location=yes, menubar=yes'); 
	//win.focus(); 
					
	setTimeout("notifyReload(win)", 1000); // check if opener window is closed for every 1 sec. 
}

/** END: myaccount upgrade step1 popup */

