function findChar(str,c){
//find index of  char c in string str

for(i = 0 ; i < str.length ; i++) 
     if(str.charAt(i) == c) return i;

     return -1 ; 
}

function findStringPortion(start,str,c){

// find a portion of a string , str ,and return it
//starting at index start , ending when char c is found. or end of the string is reached 

 			var scEnd = start ; 
		
			while(scEnd < str.length){
			   			
					if(str.charAt(scEnd) == c) break ;
						
						scEnd++; 
							
			}
 			
			return str.substring(start, scEnd) ;

}


function IsValidObject(objToTest) {
if (objToTest == null) {
return false;
}


if(objToTest == "undefined"){
return false ; 
}

if( objToTest == 'undefined'){
	return false ; 
}


return true;
}

function isValidEMail(address)
{
	
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(address)) return true
	else return false;
}



function reDirect(w){

if(w == '') {
document.location.reload();
}
else{
document.location = w ;
}


}




// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function openEmailFormWindow(sc) {



	var u = 'http://www.oag.com/NorthAmerica/mailAfriend/mailForm.asp?url=' ; 
	
	u+= escape(window.location);

	if(IsValidObject(sc)) u+=escape('&src='+sc);	

	popupWin = window.open(u,'mailForm','width=450,height=386,left=100,top=100,screenX=100,screenY=100');

}

function cleanElement(element)
{
	var el = element;
	el.parentNode.removeChild(el);
}

function forgotPassword(formName, pageName)
{
	var form = eval("document." + formName);
	form.pageName.value = pageName;
	form.action = "https://safe.oag.com/cart/OAGForgotPassword.do";
	form.submit();
}

