﻿function popup(id, ds, s) {
	var url = "/Popup_g.asp?p=" + WebPage + "&id=" + id;
	var w='';
	if (ds != '') url += "&ds=" + ds;
	if ( s != '') url += "&s=" + s;

    if (!w.closed && w.location)
    {
        w.focus();
    }
    else
    {
    	w = window.open(url, "", "scrollbars=1,location=0,status=0,menubar=0,resizable=1,width=458,height=580");
    }
    if (!w.opener)
    {
        w.opener=self;
    }
    else
    {
        w.focus();
    }

	if (!w) {
		alert("Unable to open popup window. You may have to disable your popup blocker for this site to work.");
	}
	return false;
}

function sendToMobile(filetype,file,cap) {
	file = escape("http://" + location.hostname + file);
	cap = escape(cap);
	
	if (filetype == 'm') {
		window.open('http://mpush.txtnation.com/req.php?account=naughtyart&video='+file+'&caption='+cap,'_MPUSH','width=640,height=420,titlebar=1,resizable=1, scrollbars=0');
	}
	else {
		window.open('http://mpush.txtnation.com/req.php?account=naughtyart&image='+file+'&caption='+cap,'_MPUSH','width=640,height=420,titlebar=1,resizable=1, scrollbars=0');
	}
		
	return false;
}

function editCard(id) {
	window.open('/Ecard.asp?id='+id, "ecard", "width=640,height=420,titlebar=0,resizable=1,scrollbars=0"); 
	return false;
}

function viewCard(n) {
	var code;
	
	code = document.getElementById('ecard' + n).value;
	if (code.length != 16) {
		alert("Invalid access code provided.  Please check and try again.");
	}
	else {
		window.open('/Ecard.asp?code='+code, "ecard", "width=640,height=420,titlebar=0,resizable=1,scrollbars=0"); 
	}
	
	return false;
}

function isEmail(strData) {
	if(strData.trim().length > 0) {
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(strData)) {
			return true;
		}
	}
	
	return false;
}

function isMultipleEmail(strData) {
	if(strData.length > 0) {
		var emails = strData.split(',');
		
		n = 0;
		for (i = 0; i < emails.length; i++) {
			emails[i] = emails[i].trim();
			
			if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(emails[i])) {
				n++;
			}
		}
		if (n == emails.length) return true;
	}
	
	return false;
}

function isEmpty(strData) {
	if ((strData.length == 0)||(strData == null)) {
		return true;
	}

	//Regular expression refers any 0 or more white space with any alphabets.
	//If that expression matches with the input string it returns true, false otherwise.
	if (/^\s*(?=\w)/.test(strData)) {
		return false;
	}
	return true;
}	

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
