/**  Virtual SMEDA Web Portal - All rights reserved.
 	* Author: Tariq Murtaza
 	* File Creation Date: 01-01-2002
	* Last Modified Date: 01-10-2003
 	*/
function Helpfunc()
{
	win = open("help.php","HelpWindow","toolbar=no,directories=no,menubar=no,width=560,height=300");
}
	
	function check()
	{
		var FormName="frm_newmem";
		var err =false;
		var errp =false;
		var errw =false;
		
		if(document.forms[FormName].elements["Naam"].value.length<=0)
			err = true;
		if(document.forms[FormName].elements["FName"].value.length<=0)
			err = true;
		if(document.forms[FormName].elements["Chapter"].value=="NO")
			err = true;
		if(document.forms[FormName].elements["Memcat"].value=="NO")
			err = true;
		if(document.forms[FormName].elements["Jamaat"].value.length<=0)
			err = true;
		
		/*if(document.forms[FormName].elements["day"].value=="NO")
			err = true;
		if(document.forms[FormName].elements["month"].value=="NO")
			err = true;
		if(document.forms[FormName].elements["year"].value=="NO")
			err = true; */
		
		if(document.forms[FormName].elements["CAddress"].value.length<=0)
			err = true;
		if(document.forms[FormName].elements["CCity"].value.length<=0)
			err = true;
		if(document.forms[FormName].elements["CCountry"].value.length<=0)
			err = true;
		if(document.forms[FormName].elements["CZip"].value.length<=0)
			err = true;
		if(document.forms[FormName].elements["Email"].value.length<=0)
			err = true;
		if(document.forms[FormName].elements["expertise"].value.length<=0)
			err = true;
		if(document.forms[FormName].elements["year_exp"].value=="NO")
			err = true;	
		
		//Mandatory Fields Check
		if(err==true)
		{
			alert("Kindly fill all the Mandatory (*) fields properly")	
			return false;	
		}
		
		//Email Check
		var myString = document.forms[FormName].elements["Email"].value;
		var Strs = myString.split(",");
		for(i=0;i<Strs.length;i++)
		{
			if(!emailCheck (Strs[i]))
			{
				alert("Email address seems incorrect");
				return false;
			}	
		}
			
		// If all the Permanent Address fields are empty 'its ok'
		if(document.forms[FormName].elements["PAddress"].value.length <=0 && document.forms[FormName].elements["PCity"].value.length <=0 && document.forms[FormName].elements["PCountry"].value.length <=0 && document.forms[FormName].elements["PZip"].value.length <=0 )
			errp = true;
		// If all the Permanent Address fields are Filled 'its ok'
		if(document.forms[FormName].elements["PAddress"].value.length >0 && document.forms[FormName].elements["PCity"].value.length >0 && document.forms[FormName].elements["PCountry"].value.length >0 && document.forms[FormName].elements["PZip"].value.length >0 )
			errp = true;
		
		//Permanent Address Check
		if(errp!=true)
		{
			alert("Kindly fill all the fields for 'Permanent Address' ")	
			return false;	
		}
			
		//Qualification check
		if(document.forms[FormName].elements["doct"].value!="NO" && document.forms[FormName].elements["doct_inst"].value.length<=0)
		{
			alert("Kindly fill the 'Institute' field for selected Qualification")	
			return false;	
		}
		if(document.forms[FormName].elements["doct"].value=="NO" && document.forms[FormName].elements["doct_inst"].value.length>0)
		{
			alert("Kindly select the 'Qualification' properly")	
			return false;	
		}
		
		if(document.forms[FormName].elements["masters"].value!="NO" && document.forms[FormName].elements["masters_inst"].value.length<=0)
		{
			alert("Kindly fill the 'Institute' field for selected Qualification")	
			return false;	
		}
		if(document.forms[FormName].elements["masters"].value=="NO" && document.forms[FormName].elements["masters_inst"].value.length>0)
		{
			alert("Kindly select the 'Qualification' properly")
			return false;	
		}
		
		if(document.forms[FormName].elements["bach"].value!="NO" && document.forms[FormName].elements["bach_inst"].value.length<=0)
		{
			alert("Kindly fill the 'Institute' field for selected Qualification")	
			return false;	
		}
		if(document.forms[FormName].elements["bach"].value=="NO" && document.forms[FormName].elements["bach_inst"].value.length>0)
		{
			alert("Kindly select the 'Qualification' properly")
			return false;	
		}
		
		if(document.forms[FormName].elements["diploma"].value!="NO" && document.forms[FormName].elements["diploma_inst"].value.length<=0)
		{
			alert("Kindly fill the 'Institute' field for selected Qualification")	
			return false;	
		}
		if(document.forms[FormName].elements["diploma"].value=="NO" && document.forms[FormName].elements["diploma_inst"].value.length>0)
		{
			alert("Kindly select the 'Qualification' properly")
			return false;	
		}
		if(document.forms[FormName].elements["others"].value!="NO" && document.forms[FormName].elements["others_inst"].value.length<=0)
		{
			alert("Kindly fill the 'Institute' field for selected Qualification")	
			return false;	
		}
		if(document.forms[FormName].elements["others"].value=="NO" && document.forms[FormName].elements["others_inst"].value.length>0)
		{
			alert("Kindly select the 'Qualification' properly")
			return false;	
		}
		
		//Certification check
		
		//if(document.forms[FormName].elements["cert"].value=="NO" && document.forms[FormName].elements["cert1_desc"].value.length>0)
		//{
			//alert("Kindly select the 'Certification' properly")
			//return false;	
		//}
		
		/*if(document.forms[FormName].elements["cert2"].value=="NO" && document.forms[FormName].elements["cert2_desc"].value.length>0)
		{
			alert("Kindly Select the 'Certification' Properly")
			return false;	
		}
		if(document.forms[FormName].elements["cert3"].value=="NO" && document.forms[FormName].elements["cert3_desc"].value.length>0)
		{
			alert("Kindly Select the 'Certification' Properly")
			return false;	
		}*/
		
		
		//Place-of-work check
		// If all the Place-of-work fields are empty 'its ok'
		if(document.forms[FormName].elements["organization"].value.length <=0 && document.forms[FormName].elements["designation"].value.length <=0 )
			errw = true;
		// If all the Place-of-work fields are filled 'its ok'
		if(document.forms[FormName].elements["organization"].value.length >0 && document.forms[FormName].elements["designation"].value.length >0 )
			errw = true;
		if(errw!=true)
		{
			alert("Kindly fill All the Fields for 'Place of Work' ")	
			return false;	
		}
  }
  

function trim(sText)
{
	sText=sText.replace(/^[\s]+/g,"");
	sText=sText.replace(/[\s]+$/g,"");
	return sText;
} 

 function emailCheckssss (emailStr)
 {
 	/* The following pattern is used to check if the entered e-mail address
   	fits the user@domain format.  It also is used to separate the username
   	from the domain. */
	var emailPat=/^(.+)@(.+)$/
	/* The following string represents the pattern for matching all special
   	characters.  We don't want to allow special characters in the address. 
   	These characters include ( ) < > @ , ; : \ " . [ ]    */
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	/* The following string represents the range of characters allowed in a 
   	username or domainname.  It really states which chars aren't allowed. */
	var validChars="\[^\\s" + specialChars + "\]"
	/* The following pattern applies if the "user" is a quoted string (in
   	which case, there are no rules about which characters are allowed
   	and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   	is a legal e-mail address. */
	var quotedUser="(\"[^\"]*\")"
	/* The following pattern applies for domains that are IP addresses,
   	rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
   	e-mail address. NOTE: The square brackets are required. */
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	/* The following string represents an atom (basically a series of
   	non-special characters.) */
	var atom=validChars + '+'
	/* The following string represents one word in the typical username.
   	For example, in john.doe@somewhere.com, john and doe are words.
   	Basically, a word is either an atom or quoted string. */
	var word="(" + atom + "|" + quotedUser + ")"
	// The following pattern describes the structure of the user
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	/* The following pattern describes the structure of a normal symbolic
   	domain, as opposed to ipDomainPat, shown above. */
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


	/* Finally, let's start trying to figure out if the supplied address is
   	valid. */

	/* Begin with the coarse pattern to simply break up user@domain into
   	different pieces that are easy to analyze. */
	var matchArray=emailStr.match(emailPat)
	if (matchArray==null)
	{
  		/* Too many/few @'s or something; basically, this address doesn't
     	even fit the general mould of a valid e-mail address. */
		//alert("Email address seems incorrect (check @ and .'s)")
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]

	// See if "user" is valid 
	if (user.match(userPat)==null)
	{
    	// user is not valid
    	//alert("The username in Email doesn't seem to be valid.")
    	return false
	}

	/* if the e-mail address is at an IP address (as opposed to a symbolic
   	host name) make sure the IP address is valid. */
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null)
	{
    	// this is an IP address
	  	for (var i=1;i<=4;i++)
		{
	   		if (IPArray[i]>255)
		 	{
	        	//alert("Destination IP address is invalid!")
				return false
	    	}
    	}
    	return true
	}

	// Domain is symbolic name
	var domainArray=domain.match(domainPat)
	if (domainArray==null)
	{
		//alert("The domain name in Email doesn't seem to be valid.")
    	return false
	}

	/* domain name seems valid, but now make sure that it ends in a
   	three-letter word (like com, edu, gov) or a two-letter word,
   	representing country (uk, nl), and that there's a hostname preceding 
   	the domain or country. */

	/* Now we need to break up the domain to get a count of how many atoms
   	it consists of. */
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3)
	{
   		// the address must end in a two letter or three letter word.
   		//alert("The address must end in a three-letter domain, or two letter country.")
   		return false
	}

	// Make sure there's a host name preceding the domain.
	if (len<2)
	{
   		var errStr="This address is missing a hostname!"
   		//alert(errStr)
   		return false
	}

	// If we've gotten this far, everything's valid!
	return true;
}

// Training programs Admin (ADD) training_program_admin_add.php
function check_valid_training(formname)
{
	
	if( trim(document.forms[formname].elements["Title"].value).length<=0 || 
	   (trim(Contents_rEdit.document.body.innerHTML).length<=0) || 
	(trim(Contents_rEdit.document.body.innerHTML)=='<P>&nbsp;</P>') || 
	(trim(Contents_rEdit.document.body.innerHTML)=='&nbsp;') )
 	 { 
	 alert('Please filled the mandatory fields');
	 return false;
	 }
	 else if( (trim(document.forms[formname].elements["nam1"].value).length>0 && 
			trim(document.forms[formname].elements["desc1"].value).length<=0) || 
			(trim(document.forms[formname].elements["nam1"].value).length<=0 && 
			trim(document.forms[formname].elements["desc1"].value).length>0) )
	 { 
	 alert('Please filled the mandatory fields in Trainers 1');
	 return false;
	 }
	else if( (trim(document.forms[formname].elements["nam2"].value).length>0 && 
			trim(document.forms[formname].elements["desc2"].value).length<=0) || 
			(trim(document.forms[formname].elements["nam2"].value).length<=0 && 
			trim(document.forms[formname].elements["desc2"].value).length>0) )
	 { 
	 alert('Please filled the mandatory fields in Trainers 2');
	 return false;
	 }
	else if( (trim(document.forms[formname].elements["nam3"].value).length>0 && 
			trim(document.forms[formname].elements["desc3"].value).length<=0) || 
			(trim(document.forms[formname].elements["nam3"].value).length<=0 && 
			trim(document.forms[formname].elements["desc3"].value).length>0) )
	 { 
	 alert('Please filled the mandatory fields in Trainers 3');
	 return false;
	 }
	 else	  
		return true;

}


// Training programs Admin (ADD ALL) training_program_admin_add_all.php
function check_valid_TrainingALL(formname)
{
	if( trim(document.forms[formname].elements["Title[1]"].value).length<=0 || 
	document.forms[formname].elements["MonthSDate[1]"].value=="NO" || 
	document.forms[formname].elements["DaySDate[1]"].value=="NO" || 
	document.forms[formname].elements["YearSDate[1]"].value=="NO" || 
	document.forms[formname].elements["CityID[1]"].value=="0" )
 	 { 
		 alert('Please filled atlest one row of Training Program');
		 return false;
	 }
	 else	  
		return true;

}


// Bussiness Match Making Admin (ADD/Modify)
function check_valid_BMM(formname)
{
	
	if(trim(document.forms[formname].elements["Title"].value).length<=0 || 
	   trim(document.forms[formname].elements["Description"].value).length<=0)
	 { 
	 alert('Please filled the mandatory fields');
	 return false;
	 }
	 else	  
		return true;

}

function CheckEmptyName(formname)
{
	if ( trim(document.forms[formname].elements["newfilename"].value).length<=0 )
	{
		alert("Please specify new file-name");
		return false;
	}
}


function check_ChangePassword(formname)
{

	if( trim(document.forms[formname].elements["NewPassword"].value).length<=0 || trim(document.forms[formname].elements["ReconfirmPassword"].value).length<=0 )
	 	{ alert('Blank Entries are Not Allowed');
		 return false;
		 }
	 else if (trim(document.forms[formname].elements["NewPassword"].value)!=trim(document.forms[formname].elements["ReconfirmPassword"].value) )
	 	 { alert('Error: Passwords Mismatch');
		 return false;
	 	 }
	 else	  
		document.forms[formname].submit();
}

function check_valid(formname)
{
	// check it is not edit form
	if(formname!='SignupFormEdit')
	{
		//check it email validity
		if (!emailCheck(document.forms[formname].elements["UserID"].value))
			return false;
		else if (document.forms[formname].elements["Agree"][1].checked)
	 	{
			alert('You should accept SMEDA agreement to become a member');
			return false;
	    }
		else if(trim(document.forms[formname].elements["Password"].value).length<=0 || 
		   trim(document.forms[formname].elements["ConfirmPassword"].value).length<=0)
		 { 
		 	alert('ERROR: Password required.');
			 return false;			
		 }
		else if (trim(document.forms[formname].elements["Password"].value)!=trim(document.forms[formname].elements["ConfirmPassword"].value))
	 	 { 
			 alert('ERROR: Passwords Mismatch');
			 document.forms[formname].elements["Password"].value="";
			 document.forms[formname].elements["ConfirmPassword"].value="";
			return false;
		 }
		 else if (trim(document.forms[formname].elements["Password"].value).length<=5)
 	 	{
			alert('ERROR: Password field length must be atleast 6 charcters long');
			document.forms[formname].elements["Password"].value="";
		    document.forms[formname].elements["ConfirmPassword"].value="";
			return false;
	
	    }

	} // if end of SignupFormEdit


}

function Check_SignIn(formname)
{
	//check it email validity
	if(emailCheck(document.forms[formname].elements["UserID"].value))
	{
		//check for blank entry in password
		if( trim(document.forms[formname].elements["Password"].value).length<=0 )
		{ 
			alert('ERROR: Password required.');
			return false;
		}
		document.forms[formname].submit();
	}
}

function check_passwords(formname)
{
	if( trim(document.forms[formname].elements["Password"].value).length<=0 )
	 { 
	 	alert('Blank Entry is Not Allowed');
	 	return false;
	 }	
	 else	  
		return true;
}

function emailCheck (emailStr)
{
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
		alert("Email address seems incorrect (check @ and .'s)");
		return false;
	}
	var user=matchArray[1]
	var domain=matchArray[2]

	if (user.match(userPat)==null) {
    	alert("The username doesn't seem to be valid.");
    	return false;
	}

	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
 		  for (var i=1;i<=4;i++) {
	    	if (IPArray[i]>255) {
	        	alert("Destination IP address is invalid!")
			return false
	    	}
    	}
    	return true
	}

	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		alert("The domain name doesn't seem to be valid.");
    	return false;
	}

	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || 
    	domArr[domArr.length-1].length>4) {
   		alert("The address must end with a valid domain.")
   		return false
	}

	if (len<2) {
   		var errStr="This address is missing a hostname!"
   		alert(errStr)
   		return false
	}

	return true;
}

function check_email(formname)
{
		if(emailCheck(document.forms[formname].elements["UserID"].value))
		{
			document.forms[formname].submit();
		}
}


/**
 * This array is used to remember mark status of rows in browse mode
 */
var marked_row = new Array;

/**
 * Sets/unsets the pointer and marker in browse mode
 *
 * @param   object    the table row
 * @param   interger  the row number
 * @param   string    the action calling this script (over, out or click)
 * @param   string    the default background color
 * @param   string    the color to use for mouseover
 * @param   string    the color to use for marking a row
 *
 * @return  boolean  whether pointer is set or not
 */
function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function

function FAQCheck(formname,FAQflag)
{
	//alert("kaka mana");
	//alert(trim(document.forms[formname].elements["Email"].value).length<=0);
	if(FAQflag==1)
		if(!emailCheck(document.forms[formname].elements["Email"].value))
			return false;
			
		if(trim(document.forms[formname].elements["Question"].value).length<=0)
		{
			alert("ERROR: Question is empty");
			return false;
		}
	return true;
}


function FeedbackCheck(formname,Feedbackflag)
{
	if(Feedbackflag==1)
	{
		if(trim(document.forms[formname].elements["Name"].value).length<=0)
		{
			alert("ERROR: Name is empty");
			return false;
		}
		else if(!emailCheck(document.forms[formname].elements["Email"].value))
			return false;
	}

			
		if(trim(document.forms[formname].elements["Comments"].value).length<=0)
		{
			alert("ERROR: Comments is empty");
			return false;
		}
	return true;
}

function SendPageCheck(formname,SendPageflag)
{
	if(SendPageflag==1)
	{
		if(trim(document.forms[formname].elements["Name"].value).length<=0)
		{
			alert("ERROR: Name is empty");
			return false;
		}
		else if(!emailCheck(document.forms[formname].elements["Email"].value))
			return false;
	}

		
		myvariable=document.forms[formname].elements["FriendsEmail"].value;
		var myArray = myvariable.split(",");

		if (myArray!=null) 
			{
		 	  for (var i=0;i<myArray.length;i++) 
	        	{	
				if(!emailCheck(trim(myArray[i])))
					return false;
				//alert(myArray[i]);
				}
			}
		
	
		if(trim(document.forms[formname].elements["Comments"].value).length<=0)
		{
			alert("ERROR: Comments is empty");
			return false;
		}
	return true;
}

//Google search function to show google logo in the background of search box
function search_blur(searchboxname)
{ 
	if (searchboxname.value == '')
	{
		//alert("in value");
		searchboxname.style.background = '#FFFFFF url(/images/google-bg-search.gif) no-repeat scroll left center';
	}
}